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

Infinite loop when starting nodemon #505

Closed
Impozible opened this issue Feb 13, 2015 · 52 comments
Closed

Infinite loop when starting nodemon #505

Impozible opened this issue Feb 13, 2015 · 52 comments

Comments

@Impozible
Copy link

Hi everyone.

I'm trying to create a simple REST api with Node, Express, Swig and MongoDB, but when I try to start my app, it runs in an infinte loop tha goes like this:

$ npm start

> [email protected] start /home/jfuertes/repositories/projects/myproject


> nodemon ./bin/www

13 Feb 12:42:27 - [nodemon] v1.3.7
13 Feb 12:42:27 - [nodemon] to restart at any time, enter `rs`
13 Feb 12:42:27 - [nodemon] watching: *.*
13 Feb 12:42:27 - [nodemon] starting `nodemon ./bin/www ./bin/www`
13 Feb 12:42:28 - [nodemon] v1.3.7
13 Feb 12:42:28 - [nodemon] to restart at any time, enter `rs`
13 Feb 12:42:28 - [nodemon] watching: *.*
13 Feb 12:42:28 - [nodemon] starting `nodemon ./bin/www ./bin/www ./bin/www`
13 Feb 12:42:28 - [nodemon] v1.3.7
13 Feb 12:42:28 - [nodemon] to restart at any time, enter `rs`
13 Feb 12:42:28 - [nodemon] watching: *.*
13 Feb 12:42:28 - [nodemon] starting `nodemon ./bin/www ./bin/www ./bin/www ./bin/www`

And so on. Do you know what could be happening?

Here is my nodemon --dump

 $ nodemon --dump
13 Feb 12:50:13 - [nodemon] v1.3.7
13 Feb 12:50:13 - [nodemon] to restart at any time, enter `rs`
13 Feb 12:50:13 - [nodemon] watching: *.*
--------------
node: v0.13.0-pre
nodemon: v1.3.7
command: node /usr/local/bin/nodemon --dump
cwd: /home/jfuertes/repositories/projects/myproject
OS: linux x64
--------------
{ run: false,
  system: 
   { cwd: '/home/jfuertes/repositories/projects/myproject',
     useFind: false,
     useWatch: true,
     useWatchFile: false },
  required: false,
  dirs: [ '/home/jfuertes/repositories/projects/myproject' ],
  timeout: 1000,
  options: 
   { dump: true,
     ignore: 
      [ '.git',
        'node_modules',
        'bower_components',
        '.sass-cache',
        re: /\.git|node_modules|bower_components|\.sass\-cache/ ],
     watch: [ '*.*', re: /.*\..*/ ],
     restartable: 'rs',
     execMap: { py: 'python', rb: 'ruby' },
     stdin: true,
     verbose: false,
     stdout: true,
     execOptions: 
      { script: './bin/www',
        exec: 'nodemon',
        args: [],
        scriptPosition: 0,
        nodeArgs: undefined,
        ext: 'js',
        env: {},
        execArgs: [] },
     monitor: 
      [ '*.*',
        '!.git',
        '!/home/jfuertes/repositories/projects/myproject/node_modules/**/*',
        '!bower_components',
        '!.sass-cache' ] },
  load: [Function],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [],
  command: 
   { raw: { executable: 'nodemon', args: [ './bin/www' ] },
     string: 'nodemon ./bin/www' },
  offset: 0 }
--------------

Thank you so much in advance.

@LinusU
Copy link

LinusU commented Feb 13, 2015

@Impozible please read up on Fenced code blocks so that we can easier read your output. You'll want to edit your post with the output wrapped like this: (' should be `)

'''text
text goes here...
'''

@Impozible
Copy link
Author

Ok, I just edited my message. Thank you for your fast answer.

@hai-cea
Copy link

hai-cea commented Feb 24, 2015

I'm experiencing this issue as well. Any ideas on why this is happening?

@remy
Copy link
Owner

remy commented Feb 24, 2015

Can anyone else confirm this issue is happening on node 0.13? Or can you replicate on node stable too?

@remy
Copy link
Owner

remy commented Feb 27, 2015

Ping @hai-cea - can you confirm the version of node you're running with?

@hai-cea
Copy link

hai-cea commented Feb 27, 2015

Hi @remy - I'm using NVM - node v0.12.0

@Wenzil
Copy link

Wenzil commented May 12, 2015

Nodemon CPU usage goes through the roof whenever the ignore parameter is used. I suspect this is related.

I'm using Node v0.12.2 on Windows 7 64 bit.

@cmbankester
Copy link

Having the same issue with node 0.12.3. Let me know if you'd like any more information; I'm very motivated to get this issue figured out.

@remy
Copy link
Owner

remy commented May 21, 2015

I can't replicate this at all, so someone else will need to debug and send
a PR to fix. I'm hoping someone here will take up the challenge.
On 20 May 2015 20:09, "Christian Bankester" [email protected]
wrote:

Having the same issue with node 0.12.2. Let me know if you'd like any more
information; I'm very motivated to get this issue figured out.


Reply to this email directly or view it on GitHub
#505 (comment).

@nha
Copy link

nha commented Jul 3, 2015

I have the same problem, using express/mongo as well.

Not sure if this is relevant, but I'll add it here : I'm in a vagrant virtual machine with nfs synchronisation of the filesystem.
http://docs.vagrantup.com/v2/synced-folders/nfs.html

Usually just stopping nodemon, wainting and launch it again fixes the problem.
I have this behaviour on a ubuntu or osx host, the target vagrant vm if ubuntu 12.04.

@remy
Copy link
Owner

remy commented Aug 31, 2015

Please try the build here #625 and feedback against the issue #625.

@thedug
Copy link

thedug commented Sep 5, 2015

I'm seeing the problem as well and I'm also using vagrant with nfs

@remy
Copy link
Owner

remy commented Sep 5, 2015

@thedug please can you test the latest dev build - details on #625

@thedug
Copy link

thedug commented Sep 5, 2015

@remy How do I load this test version?

@remy
Copy link
Owner

remy commented Sep 5, 2015

Its at the top of this issue, in bold...

npm install -g nodemon@dev

On Sat, 5 Sep 2015 10:03 Douglas Ferguson [email protected] wrote:

@remy https://github.com/remy How do I load this test version?


Reply to this email directly or view it on GitHub
#505 (comment).

@thedug
Copy link

thedug commented Sep 5, 2015

Thanks,

Does the nodemon@dev trick work if I'm using package.json?

On Sat, Sep 5, 2015 at 11:50 AM, Remy Sharp [email protected]
wrote:

Its at the top of this issue, in bold...

npm install -g nodemon@dev

On Sat, 5 Sep 2015 10:03 Douglas Ferguson [email protected]
wrote:

@remy https://github.com/remy How do I load this test version?


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).

@remy
Copy link
Owner

remy commented Sep 5, 2015

I think so, I assume you mean as a local dependency.

On Sat, 5 Sep 2015 18:01 Douglas Ferguson [email protected] wrote:

Thanks,

Does the nodemon@dev trick work if I'm using package.json?

On Sat, Sep 5, 2015 at 11:50 AM, Remy Sharp [email protected]
wrote:

Its at the top of this issue, in bold...

npm install -g nodemon@dev

On Sat, 5 Sep 2015 10:03 Douglas Ferguson [email protected]
wrote:

@remy https://github.com/remy How do I load this test version?


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).

@thedug
Copy link

thedug commented Sep 5, 2015

Yeah.. Do I just add the following to my package json?

nodemon: 'dev"

Also, I'm using grunt-nodemon, will it actually use this version or it's
own version?

On Sat, Sep 5, 2015 at 1:10 PM, Remy Sharp [email protected] wrote:

I think so, I assume you mean as a local dependency.

On Sat, 5 Sep 2015 18:01 Douglas Ferguson [email protected]
wrote:

Thanks,

Does the nodemon@dev trick work if I'm using package.json?

On Sat, Sep 5, 2015 at 11:50 AM, Remy Sharp [email protected]
wrote:

Its at the top of this issue, in bold...

npm install -g nodemon@dev

On Sat, 5 Sep 2015 10:03 Douglas Ferguson [email protected]
wrote:

@remy https://github.com/remy How do I load this test version?


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).

@remy
Copy link
Owner

remy commented Sep 5, 2015

I don't know about how other packages work. I'm not sure grunt-nodemon uses
peer dependencies, so you'll need to open an issue on their repo to ask for
a dev build version.

When I use nodemon as a direct dependency I'd install as simply npm install -D nodemon@dev

On Sat, 5 Sep 2015 19:19 Douglas Ferguson [email protected] wrote:

Yeah.. Do I just add the following to my package json?

nodemon: 'dev"

Also, I'm using grunt-nodemon, will it actually use this version or it's
own version?

On Sat, Sep 5, 2015 at 1:10 PM, Remy Sharp [email protected]
wrote:

I think so, I assume you mean as a local dependency.

On Sat, 5 Sep 2015 18:01 Douglas Ferguson [email protected]
wrote:

Thanks,

Does the nodemon@dev trick work if I'm using package.json?

On Sat, Sep 5, 2015 at 11:50 AM, Remy Sharp [email protected]
wrote:

Its at the top of this issue, in bold...

npm install -g nodemon@dev

On Sat, 5 Sep 2015 10:03 Douglas Ferguson [email protected]
wrote:

@remy https://github.com/remy How do I load this test version?


Reply to this email directly or view it on GitHub
<#505 (comment)
.


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).


Reply to this email directly or view it on GitHub
#505 (comment).

@remy
Copy link
Owner

remy commented Sep 12, 2015

#625 closes and released in [email protected]

@remy remy closed this as completed Sep 12, 2015
@ORESoftware
Copy link

getting this in 2017, I have used nodemon a couple times before, not a newb with this, cannot figure out why it keeps restarting! will report back if I figure it out.

@tonespy
Copy link

tonespy commented Feb 24, 2017

@ORESoftware I've been experiencing this for over a week now. And I don't seem to understand anymore either. I containerized my application and still the same thing.

@remy
Copy link
Owner

remy commented Feb 24, 2017

Worth opening a new issue and including the nodemon version, node version, npm or yarn (doubt if it makes a difference), and OS.

@ORESoftware
Copy link

I love Nodemon, the functionality it provides is critical to fast development.
I will come back to Nodemon, but if you need a script that does the job, you can use this

https://medium.com/@the1mills/diy-nodemon-5176fdcc1cfb#.t650qxq40

it was less time to write the script than to debug nodemon as is. I don't intend to undermine Nodemon, I simply intend to help people who might be in a bind like I was, I could not figure out why it keeps restarting. So bizarre.

@remy
Copy link
Owner

remy commented Feb 25, 2017 via email

@the1mills
Copy link

I believe that! I saw hundreds of commits and 10s of branches and I was too afraid to look at the code as is. Now that I have tried my hand at I will take a look and the feature creep that took place!

One thing I definitely found that I wanted - as a user I would like to tell Nodemon whether I want Nodemon to send SIGTERM, SIGINT or SIGKILL to my process.

@remy
Copy link
Owner

remy commented Feb 25, 2017 via email

@tonespy
Copy link

tonespy commented Mar 1, 2017

@ORESoftware in my case, I noticed it's tracking my .tmp/ directory and npm-log. So, all I did was include a .nodemonignore and all the files I don't want to bother about.

@mdxprograms
Copy link

@tonespy that worked for me as well

@chr4ss1
Copy link

chr4ss1 commented Aug 17, 2017

still getting this. some info about my config:

OSX
nodemon 1.11.0

my package json:

"dev": "concurrently \"npm run tstojs-watch\" \"npm run watch\"",
"tstojs-watch": "tsc -w",
"watch": "nodemon --watch dist --watch .env ./dist/index.js",

the command I run:

npm run dev

It just keeps saying "restarting due to file changes" and then crashes.

some of the versions:
"concurrently": "3.1.0",
"typescript": "2.3.4",

Don't have time to pursue it further at the moment, doing the manual compile & run method for now. The key why it goes in to forever loop is because of the tsc task runner, I have no idea what's going on. They are feeding off each other somehow.

@arxpoetica
Copy link

This seems to be happening on the latest version of Nodemon. I backed up to 1.11.0 and all systems go.

@jonasnas
Copy link

jonasnas commented Nov 25, 2017

I get this infinite loop if nodemon is run with npm start => nodemon app.js but it works fine if I run nodemon directly, which eventually runs npm start => node app.js

@ORESoftware
Copy link

ORESoftware commented Nov 25, 2017

Yeah I would avoid using npm start to start your app/server, remove that entry from package.json and nodemon won't use it

@Airboy
Copy link

Airboy commented Dec 26, 2017

I encountered the same issue. This bug is not related to nodemon but to another dependency: user-agent. This later regenerates on the fly a file based on a remote database (regexps.js). Because of it and the way it is generated, nodemon restart in loop.

By using the verbose mode in my nodemon.json, I was able to find the related file.

I hope this explanation should help others with this issue.

@arxpoetica
Copy link

@Airboy not following. What do you mean by "verbose mode"?

@arxpoetica
Copy link

And what's the correct way to fix this problem?

@Airboy
Copy link

Airboy commented Dec 26, 2017

You merely have to add the following option "verbose": true into your nodemon.json (config file for nodemon).

In this mode, nodemon should display the file causing its restart. I don't guarantee that you can quickly solve your problem, but it's a good start to find the cause of this issue.

In my case, I found that the regexps.js was the file in question. Thus I simply force nodemon to ignore it by updating my nodemon.json file as follows:

 "ignore": [
    "regexps.js"
  ],

@remy
Copy link
Owner

remy commented Dec 26, 2017

A fairly common example of nodemon looping restarts is when the application creates a file during start-up that's caught be nodemon watch filters, which triggers a restart, and then the entire process goes into a loop.

Run nodemon --verbose and it will report what's restarting the process and why (so you can explicitly ignore that file or pattern).

@arxpoetica
Copy link

@remy yes, I've seen those problems happen before, and didn't equate the two. That was probably what was happening all along. False positive. Thanks.

@arxpoetica
Copy link

Nope. I take it back. I ran verbose and files that are in .nodemonignore are no longer ignored on the upgrade.

Am I doing the pattern wrong?

/client/*
/public/*

@remy
Copy link
Owner

remy commented Jan 3, 2018

@arxpoetica I think that's an absolute path, so assuming that /public is at the root of your drive, then it should work. Otherwise try ./public/*.

@arxpoetica
Copy link

arxpoetica commented Jan 3, 2018

I found the problem. It's reading package.json before .nodemonignore -->

[nodemon] reading config /Users/.../package.json

Why would it do that if I have a nodemonignore file already?

@arxpoetica
Copy link

I mean, I can just switch to the modern convention, which is what I'll do. (Tho' I prefer the old way.)

@remy
Copy link
Owner

remy commented Jan 3, 2018

Oh yes, if there's nodemonConfig in the package.json, then IIRC that will take over.

@remy
Copy link
Owner

remy commented Jan 3, 2018

Wait…sorry, I spoke too early. That log just means it's checking. I'm just checking the source code now…

@arxpoetica
Copy link

To be clear, I don't have nodemonConfig in package.json

@remy
Copy link
Owner

remy commented Jan 3, 2018

I'm reading the code (and will open a new issue) because the logging around where the config came from isn't clear (at all!).

Can you run your nodemon command (as you are already) but with --dump and include the output here? It'll help me see whether it read a config or not.

@arxpoetica
Copy link

Yup. Probably good to still open an issue, though I just got it working correctly!

@remy
Copy link
Owner

remy commented Jan 3, 2018

That wasn't the --dump, but it's fine if you've got it sorted 😉

@arxpoetica
Copy link

Yeah, sorry, I figured that out right after I posted (and promptly deleted). Here's the actual dump:

[nodemon] 1.14.7
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
--------------
node: v9.2.0
nodemon: 1.14.7
command: /Users/americanyak/.nvm/versions/node/v9.2.0/bin/node /Users/[...path ommitted...]/project-y/node_modules/.bin/nodemon --dump -r @std/esm server.js
cwd: /Users/[...path ommitted...]/project-y
OS: darwin x64
--------------
{ run: false,
  system:
   { cwd: '/Users/[...path ommitted...]/project-y' },
  required: false,
  dirs:
   [ '/Users/[...path ommitted...]/project-y' ],
  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: /.*\..*/ ],
     ignoreRoot:
      [ '**/.git',
        '**/.nyc_output',
        '**/.sass-cache',
        '**/bower_components',
        '**/coverage',
        '**/node_modules' ],
     restartable: 'rs',
     colours: true,
     execMap: { py: 'python', rb: 'ruby' },
     stdin: true,
     runOnChangeOnly: false,
     verbose: false,
     signal: 'SIGUSR2',
     stdout: true,
     watchOptions: {},
     execOptions:
      { script: 'server.js',
        exec: 'node',
        args: [ '-r', '@std/esm' ],
        scriptPosition: 2,
        nodeArgs: undefined,
        execArgs: [],
        ext: 'js,mjs,json',
        env: {} },
     monitor:
      [ '*.*',
        '!**/.git',
        '!**/.nyc_output',
        '!**/.sass-cache',
        '!**/bower_components',
        '!**/coverage',
        '!**/node_modules' ] },
  load: [Function],
  reset: [Function: reset],
  lastStarted: 0,
  loaded:
   [ '/Users/[...path ommitted...]/project-y/package.json' ],
  watchInterval: null,
  signal: 'SIGUSR2',
  command:
   { raw: { executable: 'node', args: [ '-r', '@std/esm', 'server.js' ] },
     string: 'node -r @std/esm server.js' } }
--------------

@dotspencer
Copy link

My two bits... Try updating nodemon.
I was using v1.11 and upgrading to v1.18.3 fixed the issue.

@dionisoros
Copy link

dionisoros commented Oct 25, 2019

My solution: add nodemonConfig in package.json file in order to stop infinite loop. In package.json:
"nodemonConfig": { "ext": "js", "ignore": ["*.test.ts", "db/*"], "delay": "2" }, "scripts": { "start": "nodemon" }

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

No branches or pull requests