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

Restarting multiple times #763

Closed
nathanmarks opened this issue Jan 22, 2016 · 55 comments
Closed

Restarting multiple times #763

nathanmarks opened this issue Jan 22, 2016 · 55 comments

Comments

@nathanmarks
Copy link

Hey,

Posting a new issue since #508 is closed.

Refer to my last comment: #508 (comment)

...

@remy I'm on 1.8.1 and seeing this behaviour. When I hit save on a single file it is restarting multiple times.

[nodemon] files triggering change check: test/integration/linkRelevancy.js
[nodemon] matched rule: **/Users/PoweredbySearch/Development/repos/poweredbysearch/link-building-tools/test/**/*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] test/integration/linkRelevancy.js

[nodemon] starting `npm run -s test`
[nodemon] child pid: 77803
[nodemon] files triggering change check: test/integration/linkRelevancy.js
[nodemon] matched rule: **/Users/PoweredbySearch/Development/repos/poweredbysearch/link-building-tools/test/**/*
[nodemon] changes after filters (before/after): 1/1
[nodemon] restarting due to changes...
[nodemon] test/integration/linkRelevancy.js

[nodemon] starting `npm run -s test`
[nodemon] child pid: 77859
@nathanmarks
Copy link
Author

Ok something batshit insane is going on here -- I can trigger multiple restarts just by hitting return in my second terminal window (when open to the same folder).

$ cding into the folder also triggers nodemon restarts with seemingly random files triggering it. (--verbose tells me it is project files that are set in the watch arg, but i haven't touched them)

@nathanmarks
Copy link
Author

Ok, it seems like this is OS X + tmux related on some level -- atleast with the terminal triggered restarts. Not sure about the actual repeated restarts on file save though.

I'm using a workaround so tmux can function properly in OS X with certain services (like the sublime text CLI). @remy could this workaround be related? Here's the issue it addresses:

tmux uses the daemon(3) library function when starting its server process. In Mac OS X 10.5, Apple changed daemon(3) to move the resulting process from its original bootstrap namespace to the root bootstrap namespace. This means that the tmux server, and its children, will automatically and uncontrollably lose access to what would have been their original bootstrap namespace (i.e. the one that has access to the pasteboard service).

...

What the wrapper/workaround does:

A small wrapper could do the work of reattaching to the appropriate namespace and then execing some other program that will (eventually) need access to the per-user namespace.

Which is run on zsh.

@nathanmarks
Copy link
Author

Somewhere, something is going terribly, terribly wrong.

This is happening after I do git add -A .

image

@fourcels
Copy link

Same issue
nonmon will restart twice after save a file

osx: 10.11.3
nodemon: 1.9.1
node: 5.9
screen shot 2016-03-30 at 15 38 36

@renomateo
Copy link

@nathanmarks I thought this might be something to do with chokidar and git, but I don't see any related bugs there.

With nodemon -x 'gulp less' -w gulp -w gulpfile.js I can repeat this 100% of the time with SourceTree and viewing any commit in my history that shows a diff of gulpfile.js or any module it requires.

@tleb
Copy link

tleb commented Apr 1, 2016

If you have some task runner which modifies files, it's normal for nodemon to restart multiple times because multiple files have changed.

@manuel-di-iorio
Copy link

Yes as @tleb said, the solution is to let nodemon ignoring the folders and files which are modified by your task runner. Usually, it's the public folder with your static assets that you don't need to listen for changes with nodemon

@tleb
Copy link

tleb commented Apr 3, 2016

I would do it the other way round: watch the output directory and not the input directory because otherwise nodemon can restart before the task runner outputs the files. If the task runner is done nicely, it will only update the concerned files. If it isn't, you can add a small delay.

@nathanmarks
Copy link
Author

@tleb I'm not using a task runner, just npm run scripts

@tleb
Copy link

tleb commented Apr 3, 2016

Not only task runners, anything that watches. Babel, a JS beautify, etc. What do your scripts do?

@nathanmarks
Copy link
Author

@tleb Node scripts that run Tape tests, which is why i'm using nodemon to watch for changes

@tleb
Copy link

tleb commented Apr 4, 2016

Do those scripts touch the filesystem?

@nathanmarks
Copy link
Author

@tleb Not any folders watched by nodemon (database+redis I/O mostly). Also, there is no output directory, source = build.

@VikramTiwari
Copy link

I thought I was the only one! 😦

Happening in following cases:

  • Opening a new file
  • Switching tabs between open files

In short, it's reloading even on read events. I did a lot of changes over weekend, so wasn't sure what was causing this. But few things to mention, in case this is one off issue:

  • Using Atom as text-editor
  • Running redis server locally, but on a different directory than being watched
  • OSX 10.11.4
  • npm 3.8.6
  • node 6.1.0
  • nodemon 1.9.2

@fvgs
Copy link
Contributor

fvgs commented May 10, 2016

I'm experiencing this as well (on OS X). When I run webpack --watch, nodemon will restart twice for a single file change. The way I have things setup, nodemon is watching literally a single file, which is my output from webpack.

I also performed another test. Without webpack and with just nodemon running, I modified the file that nodemon watches and saved it. Upon saving, nodemon will restart 3 or 4 times, listing the same file as the trigger for each restart.

The strange thing is, I believe this behavior began recently. I've been using v1.9.1 since I began this particular project, and just a few days ago I began noticing this behavior.

@remy, any feedback on what might be causing this and how to fix it?

@remy
Copy link
Owner

remy commented May 10, 2016

@fvargas I'm really not sure. I don't see the same thing myself (using osx, [email protected] - though pretty sure the bug fix isn't related).

If you run nodemon with --verbose you should see the filename that's responsible for triggering the reload. Maybe that's a start?

@nathanmarks
Copy link
Author

nathanmarks commented May 10, 2016

@remy I see this happening hitting save on a file -- just once. Yet that file shows up as the cause for multiple restarts. (check my verbose log in my original report)

@fvgs
Copy link
Contributor

fvgs commented May 10, 2016

My results match those of @nathanmarks. The test I mentioned above involved nodemon watching a single file, which I edited and saved (using Vim), and the verbose output showed that same file as the trigger for each of the 3 or 4 restarts that would occur from that single save.

Is it possible for this issue to be something that develops over time? Like I said, I don't recall observing this issue earlier on in my project. It would explain why the problem is not as widespread and not easily reproducible.

@nathanmarks
Copy link
Author

@remy please let me know if there's anything I can do to assist in debugging this.

@remy
Copy link
Owner

remy commented May 10, 2016

OK, just reading back. I see @nathanmarks mentions tmux - is this still the case for everyone here?

Have you tried the --legacy mode (which switches to polling)? I do know that there's issues with tools like docker/containers and nodemon - which amazingly are being fixed in the docker beta (they show a demo that includes nodemon working correctly in the docker beta on a mac).

@fvgs
Copy link
Contributor

fvgs commented May 12, 2016

@remy I'm not using tmux, but the issue only occurs for me on file save.

Using legacy mode seems to fix the problem. On file save, instead of restarting four times, nodemon only restarts once, as expected.

Perhaps this provides a clearer idea of where the problem lies? As far as I can tell, my usage of nodemon is pretty standard, and I'm not using tmux or any container tools. This is my nodemon command without legacy mode:

nodemon --watch build/app.js build/app.js

Are others experiencing this issue watching a file as opposed to a directory?

@remy
Copy link
Owner

remy commented May 12, 2016

@fvargas this is very weird. So, no containers, can I ask exactly what OS? Also, is there anything special about your time on your machine? If you run date in your terminal does it give you what you expect?

@fvgs
Copy link
Contributor

fvgs commented May 12, 2016

@remy Right, no containers, and I'm running OS 10.11.4 El Capitan. The time on my machine is normal.

@fvgs
Copy link
Contributor

fvgs commented May 18, 2016

@remy I was able to resolve this issue by updating the dependencies of nodemon. In particular, I believe the issue may have been with the chokidar package which also started giving me trouble when using webpack. More specifically, when using webpack, fsevents, a dependency of chokidar, began producing a warning related to some soon-to-be-deprecated functionality in node, as a result of a recent Node 6.0+ upgrade.

Thus, I suspect upgrading fsevents to 1.0.12 may have also been what fixed the restarting issue with nodemon, though I can't be 100% certain.

For anyone still encountering this issue, I suggest installing the latest versions of all nodemon dependencies.

@fourcels
Copy link

package.json

{
  "scripts": {
    "nodemon": "nodemon index.js"
  },
}
  1. start nodemon by npm

    $ npm run nodemon

    save index.js file, nodemon will restart twice

  2. start nodemon direct

    $ nodemon index.js

    save index.js file, nodemon is all right

osx 10.11.3
nodemon 1.9.2

@fvgs
Copy link
Contributor

fvgs commented May 25, 2016

What versions of chokidar and fsevents is your nodemon installation using? Also, what version of node are you running?

Make sure chokidar and fsevents are updated to the latest version compatible with nodemon.

@fourcels
Copy link

@fvargas

chokidar and fsevents are already lastest version

@fvgs
Copy link
Contributor

fvgs commented May 26, 2016

@fourcels Upgrading fsevents to 1.0.12 seems to be what fixed it for me. If that's not the issue, I'm not sure what the fix is.

Posting your Node version may help identify the issue.

Based on the accounts of others and my own, this sort of issue seems to be related to fsevents and affects OS X users. You might try upgrading to OS 10.11.4 and see if that changes anything.

@dy-dx
Copy link

dy-dx commented May 27, 2016

Same here, I needed to npm -g uninstall nodemon and npm -g install nodemon to fix the multiple restarts

@fourcels
Copy link

@fvargas
Remove ~/.node-gyp folder and rebuild fsevent fix the issue

@cbengtson85
Copy link

seems this issue is similar to the one i just opened.
#844

@cbengtson85
Copy link

uninstalling fsevents and reinstalling seems to have fixed the issue for me

@timmeade
Copy link

Nothing here seems to fix it for me. OSX similar setup to the rest. I even installed nodemon locally to the project and it still starts twice on each save. This did not happen until i update to 6.2.2 this morning and the latest npm.

@timmeade
Copy link

I rolled back to node 5.11.1 and then uninstalled nodemon -g and reinstalled. Issue went away.

@fvgs
Copy link
Contributor

fvgs commented Jun 24, 2016

@timmeade The symptoms you describe are consistent with the diagnosis presented throughout the latter half of this thread. Keep the following two things in mind:

  1. The executable installed as part of the local installation of a package will only be used if directly invoked or if invoked within an npm script of that package. So, perhaps you were still invoking the global install even when you installed nodemon locally to your project?
  2. The way in which npm updates shared packages is not entirely straightforward. fsevents (see above) is a common package, so there may be "interference" from other packages even when you uninstall nodemon.

I suggest setting up a new, dummy package and testing it out with the local install of nodemon as described in the readme. If it works, then we know one or both of the above two points are the cause of your problem.

@psyrendust
Copy link

Adding [email protected] fixed things for me.

  "dependencies": {
    "chalk": "1.1.3",
    "express": "4.14.0",
    "fsevents": "1.0.14",
    "isomorphic-fetch": "2.2.1",
    "morgan": "1.7.0",
    "nodemon": "1.9.2",
    "proxy-middleware": "0.15.0",
    "throng": "4.0.0"
  },

@buritica
Copy link

I was having the same issue while using 1.9.2, pretty bad even to the point where I would get restarts when I switched tabs in Atom Editor, updated to 1.10.2 and stopped having 👻 restarts.

@yoshuawuyts
Copy link

[email protected] + [email protected] are not resolving this issue for me. @nathanmarks explanation of the daemon(3) namespaces seems plausible. This is heaps annoying for sure

@yoshuawuyts
Copy link

yoshuawuyts commented Aug 31, 2016

As per #508 (comment), switching back to nodemon@~1.5.0 resolves this issue

@bool3max
Copy link

Was having the same issue. Uninstalled nodemon globally (sudo npm uninstall -g nodemon), reinstalled it, now it restarts properly. Using node 7.

@Ekimoth
Copy link

Ekimoth commented Nov 3, 2016

What I found is that nodemon seems to re-run gulpfile.js on each file change, instead of just running the tasks it's supposed to run from the "tasks" array parameter.

@ghost
Copy link

ghost commented Jan 1, 2017

If you are using nvm, run which nodemon to see where it is located, and if it's somewhere outside ~/.nvm try to remove it

@thabti
Copy link

thabti commented Jan 14, 2017

I added a --delay for example nodemon lib/index.js --delay 1 and that solved the issue.

@MaffooBristol
Copy link

I had this issue when upgrading to Node 7 but still with nodemon 1.9.1. Just updating to 1.11.1 fixed it.

@snapeuh
Copy link

snapeuh commented Feb 7, 2017

I have the same issue unfortunately, on Mac. I nodemon a .js file and everytime I modify it, nodemon restarts two times. Any hint? Node v7 + Nodemon 1.11.0.

@dpkshrma
Copy link

I was facing the same issue. And it had nothing to do with any specific version of nodemon/nodejs/etcetra.
While running the command yarn run dev, it had a build command(babel src -d dist) in the predev script, which created a lot of new files.
Once I saved my changes, nodemon re-ran the dev script, which in turn ran build command, which created new files, which triggered nodemon several times again.
I resolved this issue by excluding the dist directory(nodemon --ignore dist --exec "yarn run dev")

So, this should be the most common(maybe only?) reason why nodemon restart multiple times. Hope it helps! ✌️

@dotspencer
Copy link

Running npm install -g nodemon fixed it for me.

That updated the dependencies (specifically fsevents) which I believe was causing the problem.

@gwitwer
Copy link

gwitwer commented Aug 16, 2017

I had this issue because I was doing "sudo npm start" out of habit instead of simply "npm start". I don't know why, but not using sudo fixed this for me.

@mikestopcontinues
Copy link

For those of you using nodemon AND chokidar, only binding to .on('all') after .on('ready') solved the problem.

const watcher = chokidar.watch([
    './content/**/*',
  ], {
    awaitWriteFinish: true,
  });

  // and now, the important part...

  watcher.on('ready', () => {
    watcher.on('all', () => {
      generateFn(() => {
        rs.reload();
      });
    });
  });

@remy
Copy link
Owner

remy commented Dec 15, 2017

Going to close this issue as it looks like (reading through all the comments) that the latest nodemon fixes this as it's using the latest fsevents (via chokidar).

Happy to reopen or create a new issue if we think something is still playing up.

@remy remy closed this as completed Dec 15, 2017
@ruslankonev
Copy link

anyway, and with latest nodemon version, on macos high sierra, when I focus on a file in atom-editor, I will have infinite restarting process...

image

@remy
Copy link
Owner

remy commented Jan 15, 2018

@ruslankonev this is a long closed issue, but your build script is generating your components directory contents, so tell nodemon to ignore that directory

@mateomarin
Copy link

uninstalling and installing did the trick

@arasmussen
Copy link

Reinstall also did the trick for me.

npm uninstall -g nodemon
npm install -g nodemon

@nicothed
Copy link

nicothed commented Aug 22, 2018

The issue started after I began using Visual Studio Code.
Uninstall and reinstall worked great, thanks!

Note that on my mac, I need to run this to see which files have been modified:
nodemon -V
(as well as --verbose)

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