Christopher Francisco
Christopher Francisco

Reputation: 16288

Nodemon stuck at "restarting due to changes..." and won't restart the server

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?

Upvotes: 15

Views: 35522

Answers (21)

Valentine Shi
Valentine Shi

Reputation: 7868

However ridiculous that could sound in 2025, re-booting my Windows 10 (with all the PATH and --ignore solutions in place) helped. That was also noted by some people around in the nodemon GitHub issues.

Upvotes: 0

gregory jonvaux
gregory jonvaux

Reputation: 51

I reinstalled an older version and it worked, like npm i -g [email protected]

Upvotes: 5

Abhiswas Patil
Abhiswas Patil

Reputation: 81

I was using Windows 10, and I faced the same issue. I used the supervisor instead of nodemon and it works perfectly.

Run the below command:

npm install supervisor -g

supervisor src/index.js

Upvotes: 8

Liu Ting Chun
Liu Ting Chun

Reputation: 189

I am using Windows 10, and I faced this issue after I accidentally removed my %PATH% variable. Try adding these three paths if this is the case:

  • C:\Windows
  • C:\Windows\system32
  • C:\Windows\System32\Wbem

Upvotes: 13

Dinith Rukshan Kumara
Dinith Rukshan Kumara

Reputation: 680

2022 update for windows 10

Go to This Pc -> properties -> Advance System Settings -> Environment variable -> User Variables.

Double click 'path' and create 'New'. Then add this path

C:\Windows\System32

Note: Make sure to close and restart your terminal.

Upvotes: 0

Jason
Jason

Reputation: 2364

Make sure nodemon isn't watching a file that you are writing to when the server starts up. You can set nodemon to ignore that (those) file(s) using the --ignore flag

for example

nodemon index.js --ignore 'something/*.json'

Upvotes: 2

yazid
yazid

Reputation: 11

open cmd as administrator and write nodemon [namefile.js]

Upvotes: -1

高欣平
高欣平

Reputation: 292

When I using the latest version of nodeJS, it won't work. But when I change back to 10.15.0, it works normally.

Upvotes: 0

Hari Krishnan
Hari Krishnan

Reputation: 1

In The Package.Json File Add Start Script As

"nodemon": "nodemon dev-server.js"

and Start The Server As

npm run nodemon

Upvotes: 0

Rupak
Rupak

Reputation: 541

Supervisior is an alternative for nodemon. It worked for me

  1. npm i supervisior -g
  2. supervisior app.js

Upvotes: 0

Belal
Belal

Reputation: 41

I was using windows 10, and I faced the same issue. I used the supervisor instead of nodemon and it started working fine for me.

Run the below command :

npm install supervisor

and in package.json add these below lines of code in the scripts key

"scripts": {"start": "supervisor app.js"}

Upvotes: 4

Muhammad Ajmal Khan
Muhammad Ajmal Khan

Reputation: 12

go to my computer's properties, click on system protection then click on advanced then click on Environment variables . There Two types of Variables. user variable and system variable. in system variable click on path then click on edit ,click on new (add three variables) %SystemRoot%\system32; %SystemRoot%; %SystemRoot%\System\Wbem then click ok .Rerun your cmd then run .it works

Upvotes: 0

Shailesh Bhokare
Shailesh Bhokare

Reputation: 592

I solved a similar issue before. I did the following things and it did work for me.

  1. npm start run:dev

  2. nodemon npm start run:dev

what is does is first i started server normally and then i used nodemon.

Upvotes: 1

Balogun Ridwan Ridbay
Balogun Ridwan Ridbay

Reputation: 670

This works for me;

Delete these directories; C:/Users/{user}/AppData/Roaming/npm and C:/Users/{user}/AppData/Roaming/npm-cache and re-installed global npm modules.

Sheers!!

Upvotes: -1

Harsha jk
Harsha jk

Reputation: 81

Nodemon is now considered to be in stale situation.So its alternative npm package supervisor can be installed globally by npm i supervisor -g and be used as supervisor filename.js

Upvotes: 0

Saurabh Mishra
Saurabh Mishra

Reputation: 335

Use below two commands:

npm install supervisor -g
supervisor src/index.js

Upvotes: 4

Shashank Kumar
Shashank Kumar

Reputation: 11

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

Upvotes: 0

Ayush Shrinkhal
Ayush Shrinkhal

Reputation: 61

Add the below path in the environment variable. It will solve your problem. %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\wbem;

Upvotes: 6

Edward
Edward

Reputation: 1

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.

Upvotes: 0

holydragon
holydragon

Reputation: 6728

Try executing

npm -g uninstall nodemon

then

npm -g install nodemon

That fixed it for me.

Upvotes: 0

Ali Raza
Ali Raza

Reputation: 9

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

Upvotes: 0

Related Questions