我的应用通过上述命令正常运行。当我更改源代码时,我希望nodemon自动重新启动。但是我收到了错误Error: listen EADDRINUSE: address already in use :::3000
。
[nodemon] starting `babel-node lib/server.js`
events.js:167
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use :::3000
at Server.setupListenHandle [as _listen2] (net.js:1294:14)
at listenInCluster (net.js:1342:12)
at Server.listen (net.js:1429:7)
at Function.listen (/Users/longntran/Desktop/learning/pangara-web/node_modules/express/lib/application.js:618:24)
at Object.listen (/Users/longntran/Desktop/learning/pangara-web/lib/server.js:12:5)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Module._compile (/Users/longntran/Desktop/learning/pangara-web/node_modules/pirates/lib/index.js:83:24)
at Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Object.newLoader [as .js] (/Users/longntran/Desktop/learning/pangara-web/node_modules/pirates/lib/index.js:88:7)
at Module.load (internal/modules/cjs/loader.js:620:32)
Emitted 'error' event at:
at emitErrorNT (net.js:1321:8)
at internalTickCallback (internal/process/next_tick.js:72:19)
at process._tickCallback (internal/process/next_tick.js:47:5)
at Function.Module.runMain (internal/modules/cjs/loader.js:778:11)
at Object.<anonymous> (/Users/longntran/Desktop/learning/pangara-web/node_modules/@babel/node/lib/_babel-node.js:224:23)
at Module._compile (internal/modules/cjs/loader.js:722:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:733:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
"dependencies": {
"ejs": "^2.6.1",
"express": "^4.16.4",
"react": "^16.6.3",
"react-dom": "^16.6.3"
},
"devDependencies": {
"@babel/core": "^7.1.6",
"@babel/preset-env": "^7.1.6",
"@babel/preset-react": "^7.0.0",
"@babel/node": "^7.0.0",
"babel-jest": "^23.6.0",
"babel-loader": "^8.0.4",
"jest": "^23.6.0",
"nodemon": "^1.18.6",
"pm2": "^3.2.2",
"prettier": "1.15.2",
"regenerator-runtime": "^0.13.1",
"webpack": "^4.26.1",
"webpack-cli": "^3.1.2"
}
我将babel 7与nodemon一起使用。请帮助我。谢谢你们
答案 0 :(得分:0)
我在此线程中找到了一个有趣的修复方法,该方法是在脚本中添加延迟和终止进程命令。
"events": {
"restart": "fuser -k 5000/tcp ; fuser -k 3050/tcp" // change to whatever ports you're using.
}
并向nodemon命令添加延迟:
--delay 1500ms
https://github.com/remy/nodemon/issues/1316#issuecomment-387367160
我还注意到,如果我快速连续地在代码编辑器中两次单击“保存”,则会收到此错误。但是,如果我只命中一次保存,就不会有问题。
答案 1 :(得分:0)
我发现在任何中断下完成正常的服务器关闭都可以使nodemon成功重启(使用Express):
// Run server
const PORT = process.env.PORT || 3000
const server = app.listen(PORT, () => {
console.log('[server] Started server');
});
// Graceful shutdown of server
process.on('SIGINT', () => {
console.log('\n[server] Shutting down...');
server.close();
process.exit();
});
process.on('SIGTERM', () => {
console.log('\n[server] Shutting down...');
server.close();
process.exit();
});
process.on('uncaughtException', () => {
console.log('\n[server] Shutting down...');
server.close();
process.exit();
});