package.json
:
{
...
"scripts": {
"start": "node start.js"
}
}
start.js
:
require('nodemon');
setTimeout(() => {}, 1e6);
In the terminal:
# Does not print anything (except `grep` itself), i.e. no node process is running
$ ps aux | grep node
# We run the `start` task then interrupt it with CTRL-C
$ yarn start
yarn run v1.6.0
node start.js
^C
# yarn was killed, but not `start.js`
$ ps aux | grep node
me 4053 0.0 0.0 4608 876 pts/2 S 14:29 0:00 /bin/sh -c node start.js
me 4054 0.0 0.0 873592 28564 pts/2 Sl 14:29 0:00 node start.js
Without the require('nodemon')
line, the start.js
process would be properly killed by yarn.
Note that this is not a problem with npm run
. It might be related (not sure) to https://github.com/yarnpkg/yarn/issues/4667. The reason I submit an issue on Nodemon is that I think this might be a problem with Nodemon not Yarn.
When being required, Nodemon installs a SIGINT
event handler. When yarn gets a CTRL-C
, it forwards it to script.js
but this is a noop because SIGINT
has an event handler.
The example is a bit contrived in order to pinpoint the problem, but in a real life scenario:
setTimeout()
I have gulp.watch()
CTRL-C
when Gulp is run through YarnOne workaround is to conditionally require Nodemon only when I am going to instantiate it, but this feels more like a hack than a real solution.
Versions: Node.js 8.11.0, Nodemon 1.17.3, yarn 1.6.0, Ubuntu 17.10
It _is_ yarn, I'm able to replicate with yarn, but not with npm:
_but_ it's also something I can fix inside of nodemon too. Hang tight.
Yes the PR seems to directly fix this problem! Thanks a lot, that was fast!
@ehmicky not particularly fast, just lucky to have some down time before I have to make my kids their dinner.
@remy Not sure if it's perhaps another issue, but I still seem to be running into this.
When I run a process with nodemon
directly, no problems. When I run it with yarn
, no problem. When I combine yarn
and nodemon
, I can never get the process to exit, having to press CTRL-C twice.
I have created an SO question with more details here: https://superuser.com/questions/1594660/why-does-zsh-keep-running-after-exiting-a-process-with-ctrl-c-until-ctrl-c-is-p
See also https://github.com/remy/nodemon/issues/1647, that's exactly what I'm running into.