Avoid calling the task completion call too many times?

Given the following gulp tasks, I can successfully start the gulp, webpack, and nodemon processes, but the webpack tasks are open, so they will continue to run the completion handler when their watch / compile loop is complete.

The server task depends on the output of the client task, so I need these operations to be synchronous, therefore done

 function onBuild(done) { return function(err, stats) { if(err) { gutil.log('Error', err); if(done) { done(); } } else { Object.keys(stats.compilation.assets).forEach(function(key){ gutil.log('Webpack: output ', gutil.colors.green(key)); }); gutil.log('Webpack: ', gutil.colors.blue('finished ', stats.compilation.name)); if(done) { done(); } } } } //dev watch gulp.task('webpack-client-watch', function(done) { webpack(devConfig[0]).watch(100, function(err, stats) { onBuild(done)(err, stats); }); }); gulp.task('webpack-server-watch', function(done) { webpack(devConfig[1]).watch(100, function(err, stats) { onBuild(done)(err, stats); nodemon.restart(); }); }); gulp.task('webpack-watch',function(callback) { runSequence( 'webpack-client-watch', 'webpack-server-watch', callback ); }); gulp.task('nodemon', ['webpack-watch'], function() { nodemon({ script: path.join('server/dist/index.js'), //ignore everything ignore: ['*'], watch: ['foo/'], ext: 'noop' }).on('restart', function() { gutil.log(gutil.colors.cyan('Restarted')); }); }); 

When I change the file, the observer does his thing, and gulp complains that the called call is called again.

[15:00:25] Error: task completion callback called too many times

I looked at this, but not sure if it is applicable.

Why can I get a task completion callback called too many times? in gulp?

Basically, I just want this to work synchronously and continuously without errors.

gulp nodemon

+6
source share
1 answer

This resolved this for me: just don't name the callback parameter in your webpack-watch task. Leave it completely.
After that, the observer works normally and quickly, without complaining.

+8
source

All Articles