7

I use nodemon version 1.18.9 (Latest version as of today).

I use Visual Studio Code (VSCode). I open a terminal and execute nodemon dev-server.js but it displays this repeatedly

restarting due to changes...

as follows

nodemon-restarting

and after a few seconds it will complete its restarting process.

I use Windows 10.

Any suggestions?

holydragon
  • 6,158
  • 6
  • 39
  • 62

5 Answers5

8

package.json

   {
      "scripts": {
        "nodemon": "nodemon dev-server.js"
      },
    }

start nodemon by npm

$ npm run nodemon
save dev-server.js file, nodemon will restart twice

start nodemon direct

$ nodemon dev-server.js
save dev-server.js file, nodemon is all right

osx 10.11.3
nodemon 1.9.2

=============UPDATED ANSWER FROM COMMENTS======================

updating answer from comments as logic from comments worked for this problem.

try adding delay for some time. let me know if it works. nodemon lib/dev-server.js --delay 1 ..

whatever your directory is.

Jabongg
  • 2,099
  • 2
  • 15
  • 32
  • What exactly do I need to do? – holydragon Jan 18 '19 at 04:36
  • Remove ~/.node-gyp folder and rebuild fsevent fix the issue. Are you on mac OSX? – Jabongg Jan 18 '19 at 04:38
  • 2
    Ok, try adding delay for some time. let me know if it works. nodemon lib/dev-server.js --delay 1 .. whatever your directory is. – Jabongg Jan 18 '19 at 04:40
  • 2
    Adding --delay 1 works. I tried it but I want a way to just use the command as what it should be used. Like just nodemon dev-server.js. I don't want to remember adding --delay 1 everytime I need to do this. I will just wait for possible better solutions. If there is none then I will accept this at the end. – holydragon Jan 18 '19 at 04:44
  • Ok, well this is hillareous, but have you tried to remove the global installation of the nodemon, and reinstall it. npm uninstall -g nodemon npm install -g nodemon – Jabongg Jan 18 '19 at 04:46
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/186899/discussion-between-jabongg-and-holydragon). – Jabongg Jan 18 '19 at 04:46
  • This `--delay 1` works on starting the process. After several days of working on it, it still tends to give some repeating restart text but not as many as before. So, it doesn't entirely solve the problem. It is proved to solve the part when I call it but not when it actually detects changes and restarts itself. – holydragon Jan 21 '19 at 03:36
  • try increasing delay time for some more seconds then. It's just a hack brother. – Jabongg Jan 21 '19 at 07:00
  • 1
    Sure. I think this is the only working workaround here so far. So please update your answer to include --delay and explanation about it so other people who have this problem will easily find the solution. – holydragon Jan 21 '19 at 07:33
3

I guess you have to change the settings on the VSCode, go to File->Auto Save(unmark the option). After that the project will restart only when you use ctrl+s on the specific path.


Edit: I did some tests on my computer and I reproduced what you trying to mean, probably you are trying to use diferent extensions that nodemon does not support. Take a look on this part of the documentation:

Specifying extension watch list By default, nodemon looks for files with the .js, .mjs, .coffee, .litcoffee, and .json extensions. If you use the --exec option and monitor app.py nodemon will monitor files with the extension of .py. However, you can specify your own list with the -e (or --ext) switch like so:

nodemon -e js,jade Now nodemon will restart on any changes to files in the directory (or subdirectories) with the extensions .js, .jade.

try to run nodemon -e ts,json(all extensions that you want to be listener) dev-server.js. When I removed the extension I got the same issue of you.

Ênio Abrantes
  • 302
  • 2
  • 11
  • Could you send to me the exact nodemon script? Maybe you have to set the watching using --watch. – Ênio Abrantes Jan 17 '19 at 06:34
  • I don't know what you mean by nodemon script. I only execute this command (`nodemon dev-server.js`) in the VSCode terminal. – holydragon Jan 17 '19 at 10:38
  • Do you really need to listenner the whole application? Try to add the --watch tag to specify the path to be listener. Try: `nodemon --watch someFolder/someFile --exec dev-server.js` or `nodemon dev-server.js --watch someFolder/someFile` – Ênio Abrantes Jan 17 '19 at 19:27
  • Yes, I want to watch the whole application. I tried what you suggested with the --watch thing but it doesn't work. It still runs as what I posted in the question even when this nodemon is the only thing that is running on this whole project. – holydragon Jan 18 '19 at 04:23
  • Tried `nodemon -e js,json dev-server.js`. Doesn't work. It still displays lots of repeating restart text. – holydragon Jan 21 '19 at 01:39
  • Also I don't have any extensions installed in the VSCode. – holydragon Jan 21 '19 at 04:39
  • I am not sure, but I would say that there is an issue with nodemon and Windows 10. I have the same problems, and as far as I can remember, I never had problems in earlier versions of Windows. Just my €0.02 Ad – Ad Rienks Apr 11 '19 at 14:09
1

please set Windows Environment Path

  1. Right Click PC/My Computer
  2. Properties
  3. Environment
  4. Path --> Edit --> New
  5. Paste:- C:\Windows\System32

ok then restart VSCode

0
  1. Try to build your application without using nodemon
  2. Correct the errors, which may be the result of tslint being unable to fix something and generating a syntax error
  3. Restart your application with nodemon
yann-h
  • 521
  • 4
  • 7
0

I guess you using typescript on your code. All time dist folder update nodemon restart again and again. So I fix it adding package.json file this code block:

"nodemonConfig": { "ext": "js", "ignore": [ ".test.ts", "db/", "dist" ], "delay": "2" }

So this ignore the dist folder and not restarting again and again.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 07 '23 at 08:40