Gulp-Nodemon watches for changes and restarts ONCE only

1.1k views Asked by At

As the title says, I'm using the gulp-nodemon module in my gulp file to have nodemon restart my server when it detects a file change:

gulp.task('default', function() {
    nodemon({ script: 'dist/server/main.js',
        tasks: ['server', 'bundle', 'css', 'ejs'],
        ext: 'ejs js json'
    }).on('restart', function() {
        console.log('Restarted!');
    });
});

All the tasks I have listed are basic build tasks. When I change a file, the server restarts, but future changes are ignored:

enter image description here

What's more is that if I interrupt the process (CTRL+C) nodemon shows the restart message as if 2 instances are running at the same time:

enter image description here

Am I doing something wrong with gulp-nodemon? Or just gulp in general?

2

There are 2 answers

1
Kenny Worden On BEST ANSWER

I found out this was an issue with gulp-nodemon. It doesn't look like it will get fixed any time soon. I suggest searching for an alternative.

https://github.com/JacksonGariety/gulp-nodemon/issues/70

0
newbreedofgeek On

I had a similar issue where nodemon which was used as part of a "watch" gulp task I had - only ran ONCE and then seemed to NOT track any file code changes I was making after this.

My gulp "watch" task was running unit tests/linting and then running a build on file changes.

I discovered the issue was actually in my unit tests where I had a bad import. i.e. I was importing a code module that did not exist. Basically it was a import module error that seemed to be swallowed up by gulp and nodemon stopped monitoring changes after that.

I found the root cause by commenting out code (starting with all tests) and then traced it to the exact test file with the bad import. After I fixed the module import nodemon worked perfectly!

In summary - it's most likely a module import error in your code that is causing nodemon to behave this way but the error was being swallowed up by gulp.