The 9527 Mock port will not be automatically released every time you restart the Taro environment. An error will be reported when you restart the taro environment.
Use the node script shelljs to get the current 9527 process, and then kill the related process. It turned out that the @tarojs/ plugin-Mock 0.0.7 version fixed the problem. Process. on(‘SIGINT’)
process.on('SIGINT', function() {
/* DO SOME STUFF HERE */
process.exit()
})
Copy the code
Shelljs gets the 9527 port process and kills it
const weappPort = 9527
const portFix = () = > {
const port = weappPort
const shellinfo = shelljs.exec(`lsof -i :${port}`).stdout.trim()
const processArr = shellinfo.split('\n')
if (processArr.length === 0) {
return
}
processArr.splice(0.1) // Delete the first item
processArr.map((processItemLine) = > {
const pid = processItemLine.split(/\s+/) [1]
. / / the console log (` monitoring to port [port: ${port}] [pid: ${pid}], running, end of the process! `)
shelljs.exec(`kill -9 ${pid}`)})}Copy the code