remy / nodemon

Monitor for any changes in your node.js application and automatically restart the server - perfect for development
http://nodemon.io/
MIT License
26.26k stars 1.72k forks source link

says server restarting but changes are not reflected on the terminal #2159

Closed EledenGreen closed 6 months ago

EledenGreen commented 8 months ago

Expected behaviour

    Server to restart and reflect changes that was made on "index.js".

initial state of index.js:

const express = require('express')
const app = express()

app.use(express.json())

let notes = [
  {
    id: 1,
    content: "HTML is easy",
    important: true
  },
  {
    id: 2,
    content: "Browser can execute only JavaScript",
    important: false
  },
  {
    id: 3,
    content: "GET and POST are the most important methods of HTTP protocol",
    important: true
  }
]

app.get('/api/notes', (request, response) => {
    console.log("Checking...")
    response.json(notes)
})

const PORT = 3001
app.listen(PORT, () => {
    console.log(`nodemon running on port ${PORT}`)
})

CHANGES MADE AT :

app.get('/api/notes', (request, response) => {
    console.log("Working...")
    response.json(notes)
})

Actual behaviour

     Server restarts but changes are not reflected.

Screenshot (243)

Replicate

npm init npm install express npm install --save-dev nodemon

package.json

{
  "name": "parta",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "dev": "nodemon index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.18.2"
  },
  "devDependencies": {
    "nodemon": "^3.0.3"
  }
}

I have tried the following solutions as well:

remy commented 8 months ago

Can you try with a different shell from power shell just to rule it out (and if it's still replicates, try directly in the terminal without vs code), again just to narrow it down

EledenGreen commented 8 months ago
remy commented 8 months ago

Wow. Okay, I'll dig out the windows machine to see if I can replicate and get back to you 👍

EledenGreen commented 8 months ago

When i use node --watch index.js it starts the nodemon and now it works fine.

image

I did get the following warning: when i entered node --watch index.js:

image

But idk why the command npm run dev didn't work.

DexterHill0 commented 8 months ago

I think I'm also having a similar issue.

If I run npm run dev nodemon will watch just a single file (package.json). If I execute the nodemon command directly in the terminal it will watch 19 files, which is correct. If I change the script command and remove the --watch package.json and execute npm run dev it will watch 34 files, but none of them will trigger a restart. It detects the changes but does not rerun the command.

remy commented 8 months ago

If you simplify the project right down to the bare minimum are you still able to replicate?

DexterHill0 commented 8 months ago

Yes, I can reproduce this in a bare project. The folder structure is:

nodemon-test
│   package.json
│
└───src
    │   index.js
    │
    └───foo
            foo.js

The contents of package.json are:

{
    "name": "nodemon-test",
    "version": "1.0.0",
    "description": "",
    "main": "src/index.js",
    "scripts": {
        "dev": "nodemon --watch 'src' --watch package.json -x \"echo I restarted!\" --verbose -e \"js\""
    },
    "author": "",
    "license": "MIT"
}

The same behaviour I reported above is obsverved in this project too.

remy commented 8 months ago

@DexterHill0 why have you used this? nodemon --watch 'src' - this tells nodemon to look for a directory called 'src' including the quotes.

If you try with nodemon --watch src --watch package.json -x \"echo I restarted!\" --verbose -e \"js\" you should find it monitoring the three files…

When I changed this locally (Windows 11 using powershell in vscode), I saved the index.js and it triggers a restart echoing out the "I restarted":

SCR-20240201-lvqz

this is the same test, but with DEBUG=nodemon,nodemon* enabled:

SCR-20240201-lvll
github-actions[bot] commented 7 months ago

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

gitmeto commented 7 months ago

ISSUE RESOLVED I was able to resolve the issue with the following fix:

https://stackoverflow.com/questions/76014227/nodemon-wont-refresh-my-server-after-ive-made-changes-to-the-server-code


I just installed nodemon, version 3.0.3 and the issue persists. The server is stuck in 'Restarting due to changes'. Have to restart server to get changes which is obviously antithetical to the purpose of the package. I have tried to run with both Autosave turned on and off.

Interesting enough I do get a popup from Red Hat Dependency Analytics (Extension)

"The component analysis couldn't fetch data from the following providers: [snyk]"

I have tried doing a search for snyk but couldn't come up with anything. I also tried disabling the Red Hat Dependency extension and this did help either.

Downgrading to nodemon 3.0.0 did not resolve the issue Downgrading to express 4.0.1 did not resolve issue.

Dev environment Window 11 "express": "^4.18.2" "nodemon": "^3.0.3"

~> git --version git version 2.43.0.windows.1

remy commented 7 months ago

Via stack overflow (from the author above):

Turns out i had to add C:\Windows and C:\Windows\System32 to my PATH variable. My problem is now solved!

github-actions[bot] commented 7 months ago

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[bot] commented 6 months ago

Automatically closing this issue due to lack of activity

Vaten0x commented 1 week ago

It works after I changed these:

  1. don't use powershell on your vscode, use ubuntu or linux for it
  2. npx nodemon -L server.js

follow me on github if that helped thanks