问题
I have a pretty basic nodemon configuration. I'm fixing this legacy node 7 project that I inherited and trying to make the development process a little bit painful. First thing first, a proper restart-and-transpile process (since it's built using ES6 modules syntax).
This is my folder structure:
- src
|- index.js
- dist
|- index.js
- index.js
- nodemon.js
I run nodemon as "start:dev": "nodemon index.js"
Here's it's content:
// index.js
if (process.env.NODE_ENV === 'production') {
require('./dist/index.js');
} else {
require('babel-register')({});
require('babel-polyfill');
require('./src/index.js');
}
The idea is that the code is transpiled on runtime, so that I don't have to stop server, re-transpile, start server manually, as I have been doing before.
Last but not least, nodemon config
// nodemon.js
{
"restartable": "rs",
"ignore": [
".git",
"node_modules/**/node_modules"
],
"verbose": true,
"watch": [
"src"
],
"env": {
"NODE_ENV": "development"
},
"ext": "js json"
}
I took this setup from MERN, and I think it should work. However, when I made a change and save, it goes:
[nodemon] files triggering change check: src/index.js
[nodemon] matched rule: /Users/me/project/path/src/**/*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] src/index.js
(stuck here. it never restarts)
I've been checking the code, and the only thing that I'm unfamiliar with, that maybe be causing it I can think of would be a child_process.execFileSync()
call, that will call a java tool; and a connection pool with mysql.createPool()
(mysql
package).
Tried both in Node 7.5 and Node 8.9. Any idea of what could be wrong?
回答1:
I am using window 10, and I faced this issue after I accidentally removed my %PATH% variable. Try adding these three paths if it is the case:
C:\Windows; C:\Windows\system32; C:\Windows\System32\Wbem;
回答2:
Add the below path in the environment variable. It will solve your problem. %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\wbem;
回答3:
type : ps aux | grep node or ps aux | grep port(e.g 3000)
and find the process copy its processId then type in terminal kill -KILL processId
it will stop your process by force than again start server
回答4:
Try executing
npm -g uninstall nodemon
then
npm -g install nodemon
That fixed it for me.
回答5:
Check whether you place your code in location without write permission. (Especially who put on Desktop) If no, please move the folder to other place with write permission. Or change the folder permission.
回答6:
By default, nodemon looks for the .js file. And due to the link of other extn files with your index.js file, it couldn't restart.
node index.js -e js,hbs,html
You can mention all the extensions which are linked with your index.js file
Hope it works for you. Thanks
回答7:
Use below two commands:
npm install supervisor -g
supervisor src/index.js
来源:https://stackoverflow.com/questions/48546079/nodemon-stuck-at-restarting-due-to-changes-and-wont-restart-the-server