Search code examples
gulp

Updated to Gulp 4.0 and now have a task build error


Im updating to Gulp 4.0 but I get an error when running gulp watch, that states: AssertionError [ERR_ASSERTION]: Task never defined: build

The relevant code block in my Gulp file looks like this. What am i doing wrong?

gulp.task('server', gulp.series('build', function () {
browserSync.init(["css/*.css", "js/*.js"], {
    server: { baseDir: "./" , port: 80}
    // If you use vhosts use the line below and comment out the line above.
    //proxy: "demo.local"
});

}));


Solution

  • You have at least this error in your code:

    browserSync.init(["css/*.css", "js/*.js"], {
    

    should be:

    browserSync({
        files: ["css/*.css", ""js/*.js"]
    });
    

    browserSync.init takes an options object as its first argument.

    Secondly, the error Task never defined: xxxx I have seen this when, in your case, you call the build task - in your 'server' task before it has been defined/registered. So put the gulp.task('build'...) definition ( a registration of the task) before your 'server' task.

    Your gulpfile is erroring for this reason before getting to the other error in browserSync.init mentioned above.