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.13k stars 1.72k forks source link

Nodemon Getting Stuck in the Restarting Phase #2185

Closed AdarshGT33 closed 3 months ago

AdarshGT33 commented 4 months ago

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 4 months ago

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

AdarshGT33 commented 4 months ago

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.

https://github.com/remy/nodemon/assets/144033708/aa9db2a5-89d6-4982-be04-7dab9115d595

remy commented 4 months ago

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?

AdarshGT33 commented 4 months ago

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

https://github.com/remy/nodemon/assets/144033708/11179a25-d954-4fa8-a581-1a0b5f3c65e8

remy commented 4 months ago

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

AdarshGT33 commented 4 months ago

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

remy commented 4 months ago

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.

AdarshGT33 commented 4 months ago

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.

https://github.com/remy/nodemon/assets/144033708/651eb5a9-6e43-4e95-8c35-f671a2cd6556

remy commented 4 months ago

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 4 months ago

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

AdarshGT33 commented 4 months ago

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 4 months ago

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.

AdarshGT33 commented 4 months ago

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

https://github.com/remy/nodemon/assets/144033708/f23aedba-1cf8-440a-80ca-da5eda1100c6

remy commented 4 months ago

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.

AdarshGT33 commented 4 months ago

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:

https://github.com/remy/nodemon/assets/144033708/26662b14-a4f0-4df4-8f40-10c6e2e60a79

Please continue to help me!

remy commented 4 months ago

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).

AdarshGT33 commented 4 months ago

https://github.com/remy/nodemon/assets/144033708/b32d9f6c-d2b4-450e-9e1e-8568b2a00f53

remy commented 4 months ago

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.

AdarshGT33 commented 4 months ago

Screenshot 2024-02-23 224731

remy commented 4 months ago

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.

AdarshGT33 commented 4 months ago

Screenshot 2024-02-24 101300

AdarshGT33 commented 4 months ago

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

github-actions[bot] commented 4 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 3 months ago

Automatically closing this issue due to lack of activity