remy/nodemon

Nodemon Getting Stuck in the Restarting Phase

AdarshGT33 opened this issue · 24 comments

Issue Statement: Nodemon Getting Stuck in the Restarting Phase

Description:
I am encountering an issue with nodemon where it gets stuck in the restarting phase and does not enter the starting phase after making changes to my Node.js project. If another change is introduced, nodemon goes back to the restarting phase without entering the starting phase.

Steps to Reproduce:

Install nodemon globally (npm install -g nodemon).
Create a Node.js project with nodemon watching for changes.
Make a change to a file that triggers nodemon to restart.
Notice that nodemon gets stuck in the restarting phase and does not enter the starting phase.
Environment:

Operating System: Windows 11
Node.js Version: v20.11.1
Nodemon Version: 3.0.3
Additional Information:
I have tried updating nodemon to the latest version (3.0.3) and running with verbose logging (nodemon --verbose), but the issue persists. There are no infinite loops or other obvious issues in my code that could cause this behavior.

Below is the code that I attempted nodemon on:
const express = require('express')
const app = express()

app.get('/', function (req, res) {
res.send('Narayana')
})

app.listen(3000)

It is a sample code of express.js which is available on the express page of npm.js and is copied from the said source.

Please let me know if you need any more information to investigate this issue. Thank you for your help.

remy commented

Can you provide a screenshot (or video) of your terminal that shows nodemon getting stuck, but can you run nodemon with the --verbose flag too

Here is the video showcasing the issue, I do not have a say in whether the nodemon executed the --verbose flag or not, I am a little confused. But most probably it seems like it executed.

script.js.-.BackEnd.-.Visual.Studio.Code.2024-02-20.09-57-55.mp4
remy commented

I need the --verbose flag to be able to see what's triggering the restart. Can you add it between nodemon and your script and rerun?

I tried to apply what you asked for and this is how it turned out..

script.js.-.BackEnd.-.Visual.Studio.Code.2024-02-20.13-59-50.mp4
remy commented

Nothing visible I'm afraid...looks like your upload failed

I re-uploaded the file, thank you for your patience.

remy commented

Your file is auto saving, so yep, it'll constantly cause nodemon to restart.

Turn off the feature in VSCode and it'll only restart when you manually trigger a save.

I tried your suggestion hopefully but I don't think it works as you and I expected it to work. I am attaching a video for reference but let me state what I did. So building onto your suggestion, I uninstalled the extension and now the nodemon enters the restarting phase after I save the changes manually but it does not start on its own.

index.js.-.endgame.-.Visual.Studio.Code.2024-02-21.06-51-27.mp4
remy commented

I don't see where you're testing that it didn't start... Are you reloading a browser off screen or running a curl?

remy commented

Just add a console.log to your code, if it's starts, you'll see the echo.

I don't see where you're testing that it didn't start... Are you reloading a browser off-screen or running a curl?

Well I quite don't understand what are you suggesting here but I guess I wasn't very clear myself and the issue we were originally discussing, still persists but when my app crashes due to errors, the nodemon works as it should.
For starters, I will try your insightful suggestions and will report back to you the outcome.

remy commented

Right, let's rewind a bit.

Use the following code (it's a slight modification on your first version, except we're logging):

const express = require('express');
const app = express();
app.get('/', function (req, res) {
  res.send('Changes');
});
app.listen(3000);
console.log('Server running at http://localhost:3000/')

Now, run nodemon --verbose with the script, then edit your script and hit save. If you can record that whole process that would be useful.

I ran the command you asked me for and here's how it went

script.js.-.BackEnd.-.Visual.Studio.Code.2024-02-22.08-32-19.mp4
remy commented

Re-opening now that I can see what you're facing. I'm pretty confident this is a problem with your particular set up (though I'd still like to resolve it), as this is the bread and butter functionality of nodemon so it should work.

I've installed a fresh copy of Win7, vscode and nodemon and can't replicate, so again, I'm sure this is your setup, but I'll try to help.

In the powershell session, before you run nodemon, can you run the following command:

$env: DEBUG="nodemon, nodemon: *"

Then run nodemon as you were, make a change and save. It should spit out a lot more debug. Again, if you can record it, it means I can see what's going on.

First of all, I am overwhelmed by your attempts to help me with an issue that after a few interactions was obvious that it is a personal setup issue, not something related to your product.
[P.S.: You have been of more help than my teachers at college had ever been during the entirety of the course. All of the conversations we had were insightful and encouraging.
As a new guy learning all of these stacks and coming across these obstacles, an individual like you is truly a blessing]

This is the video showcasing the runtime state of the above command:

script.js.-.BackEnd.-.Visual.Studio.Code.2024-02-23.06-33-50.mp4

Please continue to help me!

remy commented

Darn, I wrote the command wrong, there shouldn't have been a space.

It's:

$env:DEBUG="nodemon,nodemon:*"

When you run nodemon, it should start giving more debug like this screenshot:

SCR-20240223-kdzc

(no worries on helping, I got the sense that you were a beginner and it's no good me just saying: "the problem is your system" and hoping you'll solve it alone - we've all got to start somewhere and somewhere along the line, someone has to give us a hand).

script.js.-.BackEnd.-.Visual.Studio.Code.2024-02-23.16-59-10.mp4
remy commented

great, and now in the same session (i.e. after you hit enter), run nodemon and repeat the saved change to see what logs are coming out.

remy commented

sorry, I need to be clearer. Follow these steps:

  1. set the debug environment value (which you're doing correctly)
  2. run nodemon --verbose .\script.js
  3. wait for it to be running (and log the message "Server running…")
  4. edit and save your script.js file
  5. observe what happens

What we're trying to establish is what nodemon is seeing when you make a change and why the script isn't fully running when the change is observed.

Also, if you don't mind me asking, I want to contribute to open-source projects and all these different sorts of things that GitHub is known for. Can I ask you to mentor me as you seem experienced enough, more than enough

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

Automatically closing this issue due to lack of activity