Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nodemon does not restart server, stuck on ---> [nodemon] restarting due to changes... #1956

Closed
JoeyFlaum opened this issue Nov 17, 2021 · 21 comments
Labels
stale no activity for 2 weeks

Comments

@JoeyFlaum
Copy link

JoeyFlaum commented Nov 17, 2021

  • Versions:
  • nodemon -v:2.0.15
  • Operating system/terminal environment (powershell, gitshell, etc): node@v16.13.0, win32@10.0.19043 / Git Bash
  • Using Docker? What image: No
  • Command you ran:
    npm start

Expected behaviour

Expected behavior is nodemon restarting the server after saving changes in the js/json files.

server.js file

const http = require('http');

const server = http.createServer((req, res) => {
  res.setHeader('Content-type', 'text/plain');
  res.write('Hello');
  res.end();
});

const PORT = 3000

server.listen(PORT, () => console.log(`Server is running on port ${PORT}`));

package.json

{
  "name": "nodejs",
  "version": "1.0.0",
  "description": "learn HTTP",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon server.js"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/JoeyFlaum/Node.js.git"
  },
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/JoeyFlaum/Node.js/issues"
  },
  "homepage": "https://github.com/JoeyFlaum/Node.js#readme",
  "devDependencies": {
    "nodemon": "^2.0.15"
  }
}

Actual behaviour

$ npm start

> nodejs@1.0.0 start
> nodemon server.js

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
Server is running on port 3000
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...
[nodemon] restarting due to changes...

Steps to reproduce

  1. Start the server with npm start command.

  2. save either the package.json file or server.js file

  3. nodemon does not restart the server.


If applicable, please append the --dump flag on your command and include the output here ensuring to remove any sensitive/personal details or tokens.

> nodejs@1.0.0 start
> nodemon --dump server.js

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
--------------
node: v16.13.0
nodemon: 2.0.15
command: C:\Program Files\nodejs\node.exe D:\Joey\WebDev\NodeJs\node_modules\nodemon\bin\nodemon.js --dump server.js   
cwd: D:\Joey\WebDev\NodeJs
OS: win32 x64
--------------
{
  run: false,
  system: { cwd: 'D:\\Joey\\WebDev\\NodeJs' },
  required: false,
  dirs: [ 'D:\\Joey\\WebDev\\NodeJs' ],
  timeout: 1000,
  options: {
    dump: true,
    ignore: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**',
      re: /.*.*\/\.git\/.*.*|.*.*\/\.nyc_output\/.*.*|.*.*\/\.sass\-cache\/.*.*|.*.*\/bower_components\/.*.*|.*.*\/coverage\/.*.*|.*.*\/node_modules\/.*.*/
    ],
    watch: [ '*.*', re: /.*\..*/ ],
    monitor: [
      '*.*',
      '!**/.git/**',
      '!**/.nyc_output/**',
      '!**/.sass-cache/**',
      '!**/bower_components/**',
      '!**/coverage/**',
      '!**/node_modules/**'
    ],
    ignoreRoot: [
      '**/.git/**',
      '**/.nyc_output/**',
      '**/.sass-cache/**',
      '**/bower_components/**',
      '**/coverage/**',
      '**/node_modules/**'
    ],
    restartable: 'rs',
    colours: true,
    execMap: { py: 'python', rb: 'ruby', ts: 'ts-node' },
    stdin: true,
    runOnChangeOnly: false,
    verbose: false,
    signal: 'SIGUSR2',
    stdout: true,
    watchOptions: {},
    execOptions: {
      script: 'server.js',
      exec: 'node',
      args: [],
      scriptPosition: 0,
      nodeArgs: undefined,
      execArgs: [],
      ext: 'js,mjs,json',
      env: {}
    }
  },
  load: [Function (anonymous)],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [],
  watchInterval: null,
  signal: 'SIGUSR2',
  command: {
    raw: { executable: 'node', args: [ 'server.js' ] },
    string: 'node server.js'
  }
}
--------------
@remy
Copy link
Owner

remy commented Nov 17, 2021

Can you also run with --verbose so we can see what's triggering the restart.

Also, are you running in the bare terminal or via an IDE like VS Code (sorry, all these things add to complexity it turns out).

@JoeyFlaum
Copy link
Author

JoeyFlaum commented Nov 17, 2021

@remy


$ npm start

> nodejs@1.0.0 start
> nodemon --verbose server.js

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 4420 to restart 
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node server.js`
[nodemon] forking
[nodemon] child pid: 13760
[nodemon] watching 3 files
Server is running on port 5000

I am using the VS Code Bash terminal.

$ git --version
git version 2.33.1.windows.1

Seeing the below, I did notice VS code has a different Node.js version than I am running. Is this an issue?
image

@remy
Copy link
Owner

remy commented Nov 17, 2021

Sorry, that wasn't very clear. What I need to see with verbose is when it's restarting as it should show what files are triggering the restart.

@JoeyFlaum
Copy link
Author

JoeyFlaum commented Nov 17, 2021

@remy

Is this what you are looking for?

$ npm start

> nodejs@1.0.0 start
> nodemon --verbose server.js

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 3700 to restart 
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node server.js`
[nodemon] forking        
[nodemon] child pid: 8524
[nodemon] watching 3 files
Server is running on port 5000
[nodemon] files triggering change check: server.js            <-------Save command
[nodemon] matched rule: **\*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] server.js

@remy
Copy link
Owner

remy commented Nov 18, 2021

Yes, but with the restart loop happening ... I'm assuming it's still a problem?

@JoeyFlaum
Copy link
Author

JoeyFlaum commented Nov 18, 2021

Yes, but with the restart loop happening ... I'm assuming it's still a problem?

Yes, it is still stuck. The terminal code I pasted is after saving the server.js file. The console output does not show up/server restart does not happen.

Thanks for the help!

@chris-strudel
Copy link

chris-strudel commented Jan 8, 2022

I'm seeing this behavior as well. I wonder if it's a Node version thing.

Windows 10
Node 14.18.1

nodemon --verbose app.js

[nodemon] 2.0.15
[nodemon] to restart at any time, enter rs
[nodemon] or send SIGHUP to 8460 to restart
[nodemon] watching path(s): .
[nodemon] watching extensions: js,mjs,json
[nodemon] starting node app.js
[nodemon] forking
[nodemon] child pid: 16772
[nodemon] watching 3 files
[nodemon] files triggering change check: app.js
[nodemon] matched rule: **.
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] app.js

I should note that the, "rs" thing doesn't seem to be working either.

@ghost
Copy link

ghost commented Jan 12, 2022

I am also experiencing this behavior and rs command won't work either.

Windows 10, Node 16.13.1

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 16128 to restart
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node app.js`
[nodemon] forking
[nodemon] child pid: 21348
[nodemon] watching 43 files
[nodemon] files triggering change check: app.js
[nodemon] matched rule: **\*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] app.js

[nodemon] files triggering change check: app.js
[nodemon] matched rule: **\*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] app.js

@lorand-horvath
Copy link

lorand-horvath commented Jan 30, 2022

Is this issue similar/the same as #1971 ?

Are you guys using Git Bash as a terminal under VSCode? That might seem to be the common issue... it's a Unix shell emulated on Windows.... so not native functionality AFAIK. Try switching the terminal to CMD or PowerShell in VSCode, if you're on Windows.

@JoeyFlaum
Copy link
Author

Is this issue similar/the same as #1971 ?

Are you guys using Git Bash as a terminal under VSCode? That might seem to be the common issue... it's a Unix shell emulated on Windows.... so not native functionality AFAIK. Try switching the terminal to CMD or PowerShell in VSCode, if you're on Windows.

I tried PowerShell and CMD. Does the same thing...

@zorridge
Copy link

zorridge commented Feb 2, 2022

I added the variables below to Path in system variables and it fixed the problem for me

C:\Windows; C:\Windows\system32; C:\Windows\System32\Wbem

@siva-kishor
Copy link

I added the variables below to Path in system variables and it fixed the problem for me

C:\Windows; C:\Windows\system32; C:\Windows\System32\Wbem

Thanks @zorridge . I was facing the same issue and it actually resolved the problem.

@ghost
Copy link

ghost commented Feb 6, 2022

Hi, @lorand-horvath it appears that the problem is not related to a specific shell, but is related to the folders mentioned by @zorridge not being in the path on Windows.

I encountered this same issue while setting the path variable in my VSCode settings.

Therefore, if you are using a custom shell/setting the path environment variable, please ensure that the above mentioned folders are available in the path.

Thanks.

@ash-js
Copy link

ash-js commented Feb 25, 2022

I added the variables below to Path in system variables and it fixed the problem for me

C:\Windows; C:\Windows\system32; C:\Windows\System32\Wbem

Adding that path doesn't solve my problem ...
nodemon 2.0.15
node v16.13.2
running powershell on vscode

@mihail-valkov
Copy link

mihail-valkov commented Mar 15, 2022

Adding that path doesn't solve my problem ...

I also have this problem. My Path vars seem ok, as suggested above.
I reproduced it with the simplest express app:

app.js:

const express = require('express');
const app = express();
const PORT = process.env.PORT || 5000;
app.listen(PORT, console.log(
    `Server started on port ${PORT}`));

package.json:

{
  "dependencies": {
    "express": "^4.17.3"
  },
  "devDependencies": {
    "nodemon": "^2.0.15"
  }
}

I also tried my app with pm2 latest. And it crashes upon killing the process:

09:29:35 PM2 | pid=4536 msg=failed to kill - retrying in 100ms
09:29:35 PM2 | Process with pid 4536 could not be killed
09:29:35 PM2 | app=app id=0 pid=4536 could not be stopped

Then I tried again nodemon and when it hanged I killed the node child process manually with:
kill PID

and then it restarted monitoring successfully.
I also tested this with Git Bash with absolutely the same behaviour.
I also tested with nodemon 1.9 with absolutely the same behavior.

Versions:
nodemon 2.0.15

Visual Studio Code:
Version: 1.65.2 (user setup)
Commit: c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1
Date: 2022-03-10T14:33:55.248Z (4 days ago)

Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043

I'll appreciate any suggestions on how to make it work. Thanks!

@JoeyFlaum
Copy link
Author

I added the variables below to Path in system variables and it fixed the problem for me

C:\Windows; C:\Windows\system32; C:\Windows\System32\Wbem

Adding that path doesn't solve my problem ...
nodemon 2.0.15
node v16.13.2
running powershell on vscode

+1

@mattstief
Copy link

I am also experiencing this behavior and rs command won't work either.

Windows 10, Node 16.13.1

[nodemon] 2.0.15
[nodemon] to restart at any time, enter `rs`
[nodemon] or send SIGHUP to 16128 to restart
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json  
[nodemon] starting `node app.js`
[nodemon] forking
[nodemon] child pid: 21348
[nodemon] watching 43 files
[nodemon] files triggering change check: app.js
[nodemon] matched rule: **\*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] app.js

[nodemon] files triggering change check: app.js
[nodemon] matched rule: **\*.*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] app.js

I had this same issue. I found a workaround here #573. I changed the signal used and it works now: nodemon --signal SIGINT app.js.

@yashrajbothra
Copy link

Hey, Can you provide the full path of server.js??

Thanks

@github-actions
Copy link

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@github-actions github-actions bot added the stale no activity for 2 weeks label Jun 28, 2022
@github-actions
Copy link

Automatically closing this issue due to lack of activity

@RiverBeaver
Copy link

RiverBeaver commented Mar 23, 2024

I added the variables below to Path in system variables and it fixed the problem for me

C:\Windows; C:\Windows\system32; C:\Windows\System32\Wbem

Thank you very much. This really helped!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale no activity for 2 weeks
Projects
None yet
Development

No branches or pull requests