Cannot run gulp watch with the npm 5

Hi there!

Following the gulp course, I can’t run the watch task with the latest version of npm.

I have the as as below:

gulp.task('watch', function() {
console.log('The watch task is running.');
require("./server.js");
gulp.watch('./public/scripts/**/*.js', ['scripts']);    });

When running the gulp-watch I’m getting this error.

Error: watching ./public/scripts/**/*.js: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)
at Gulp.watch (/Gulp/node_modules/gulp/index.js:28:11)
at /Gulp/gulpfile.js:34:10
at taskWrapper (/Gulp/node_modules/undertaker/lib/set-task.js:13:15)
at bound (domain.js:395:14)
at runBound (domain.js:408:12)
at asyncRunner (/Gulp/node_modules/async-done/index.js:55:18)
at process.internalTickCallback (internal/process/next_tick.js:70:11)

What I’m missing here?

Thoughts?

TA

Missing in version of gulp (in 4.x version changes syntax for watch)
Try it:

gulp.task('watch', function() {
  gulp.watch('app/css/*.css', gulp.series('styles'));
  gulp.watch('app/js/*.js', gulp.series('scripts'));
  gulp.watch('app/img/*', gulp.series('images'));
})
1 Like

Thank you so much, yeah it works fine now. How the syntax is changed? Would you mind explaining that a bit? Could you refer to me to some useful docs as well?