Gulp报错问题,AssertionError [ERR_ASSERTION]: Task function must be specified

task任务的回调函数前必须加上 async 构成异步函数  例如:

gulp.task('cssmin', async() => {
    gulp.src(['./src/css/*.less', './src/css/*.css'])
        .pipe(less())
        .pipe(csso())
        .pipe(gulp.dest('./dist/css'));
});

报错信息中也有提示:

The following tasks did not complete: default,
Did you forget to signal async completion?

 

构建全局任务调用报错,例如:

PS C:\Users\J\Desktop\demo\gulp-demo> gulp                                                                                                     assert.js:385
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (C:\Users\J\node_modules\undertaker\lib\set-task.js:10:3)
    at Gulp.task (C:\Users\J\node_modules\undertaker\lib\task.js:13:8)
    at Object. (C:\Users\J\Desktop\demo\gulp-demo\gulpfile.js:60:6)
    at Module._compile (internal/modules/cjs/loader.js:1176:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1196:10)
    at Module.load (internal/modules/cjs/loader.js:1040:32)
    at Function.Module._load (internal/modules/cjs/loader.js:929:14)
    at Module.require (internal/modules/cjs/loader.js:1080:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at execute (C:\Users\J\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:36:18) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

 

在调用的函数名前加上gulp.series即可

gulp.task('default', gulp.series(['htmlmin', 'cssmin', 'jsmin', 'copy', async(done) => done]))

 

你可能感兴趣的:(Gulp报错问题,AssertionError [ERR_ASSERTION]: Task function must be specified)