简体   繁体   中英

Gulp-Nodemon watches for changes and restarts ONCE only

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:

在此处输入图片说明

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:

在此处输入图片说明

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM