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

20

14

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?

Flemings answered 31/1, 2018 at 15:45 Comment(1)
it's a long shot, but did you ever find a solution to this? i'm having the same problem here.Kohn
N
13

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
Nette answered 23/3, 2019 at 8:10 Comment(2)
Well I did the same mess and this helped me fix it! 10xTael
the Path should START with this(it didn't work for me when I paste it at the end of Path): %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0Westering
S
7

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

Susannsusanna answered 13/12, 2020 at 6:22 Comment(0)
T
6

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

Transmigrant answered 21/12, 2019 at 14:34 Comment(0)
F
5

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

Frodina answered 20/8, 2021 at 12:33 Comment(0)
K
4

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"}
Knopp answered 10/2, 2021 at 6:19 Comment(1)
This is the only solution that worked for me, I tried every solution on the web to fix nodemon, looks like nodemon is a no go anymore for windows users, this is the way to goVillatoro
H
3

Use below two commands:

npm install supervisor -g
supervisor src/index.js
Hallee answered 15/6, 2020 at 21:58 Comment(1)
It'd be valuable to add an explanation of what node-supervisor is and why it solves this problem.Cottonweed
F
2

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'
Fuji answered 3/2, 2022 at 4:18 Comment(1)
This lights up a lightbulb!Distinctly
R
1

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.

Rollicking answered 4/11, 2020 at 6:15 Comment(0)
S
0

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

Stephenson answered 19/6, 2018 at 11:52 Comment(0)
P
0

Try executing

npm -g uninstall nodemon

then

npm -g install nodemon

That fixed it for me.

Prediction answered 8/1, 2019 at 2:5 Comment(0)
V
0

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.

Velodrome answered 15/5, 2019 at 14:12 Comment(0)
J
0

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

Jughead answered 11/4, 2020 at 2:41 Comment(0)
F
0

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

Fair answered 3/8, 2020 at 13:29 Comment(0)
R
0

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

Reynalda answered 10/11, 2020 at 7:46 Comment(0)
C
0

Supervisior is an alternative for nodemon. It worked for me

  1. npm i supervisior -g
  2. supervisior app.js
Carboy answered 31/3, 2021 at 5:16 Comment(0)
K
0

In The Package.Json File Add Start Script As

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

and Start The Server As

npm run nodemon
Karalynn answered 10/6, 2021 at 7:10 Comment(0)
P
0

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

Partition answered 30/6, 2021 at 11:56 Comment(0)
E
0

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.

Esparza answered 11/8, 2022 at 21:16 Comment(0)
G
-1

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!!

Gradin answered 9/8, 2020 at 8:1 Comment(0)
L
-1

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

Landmark answered 28/7, 2021 at 11:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.