简体   繁体   中英

Gulp error: Task function must be specified

This is my first time using Gulp, I am trying to make a gulpfile to minify and merge css and js files, but I have this error when I run the command gulp :

C:\Users\S.Hocine\Desktop\gulpTest>gulp
AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (C:\Users\S.Hocine\Desktop\gulpTest\node_modules\undertaker\lib\set-task.js:10:3)
    at Gulp.task (C:\Users\S.Hocine\Desktop\gulpTest\node_modules\undertaker\lib\task.js:13:8)
    at Object.<anonymous> (C:\Users\S.Hocine\Desktop\gulpTest\gulpfile.js:36:6)
    at Module._compile (internal/modules/cjs/loader.js:1156:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
    at Module.load (internal/modules/cjs/loader.js:1000:32)
    at Function.Module._load (internal/modules/cjs/loader.js:899:14)
    at Module.require (internal/modules/cjs/loader.js:1042:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at requireOrImport (C:\Users\S.Hocine\AppData\Roaming\npm\node_modules\gulp-cli\lib\shared\require-or-import.js:19:11) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

my gulpfile:

const gulp = require('gulp');
const uglify = require('gulp-uglify');
const concat = require('gulp-concat');

// minify and copy html
gulp.task('minifyHtml', function(){
    gulp.src('src/*.html')
        .pipe(uglify())
        .pipe(gulp.dest('dest'));
  });

// minify and merge css
gulp.task('minifyMergeCss', function(){
    gulp.src('src/css/*.css')
        .pipe(concat('merged-min.css'))
        .pipe(uglify())
        .pipe(gulp.dest('dest/css'));
  });

// minify and merge js
gulp.task('minifyMergeJs', function(){
  gulp.src('src/js/*.js')
      .pipe(concat('merged-min.js'))
      .pipe(uglify())
      .pipe(gulp.dest('dest/js'));
});

gulp.task('default', ['minifyHtml', 'minifyMergeCss', 'minifyMergeJs']);

gulp.task('watch', function(){
  gulp.watch('src/*.html', ['minifyHtml']);  
  gulp.watch('src/css/*.css', ['minifyMergeCss']);
  gulp.watch('src/js/*.js', ['minifyMergeJs']);
});

my gulp version:
CLI version: 2.3.0
Local version: 4.0.2

Where is the problem?

If you uses the gulp version V3 that contain the different syntax use the latest version of gulp, and also for gulp task modules that you are using into latest version if that doesn't work too use this way,

An example of your function it must be,

    gulp.task('default', gulp.series('minifyHtml', 'minifyMergeCss', 'minifyMergeJs'));

Now that'll work fine. This happens because of in gulp v4 the list parameter has been deprecated.

see the more robust example in the gulp documentation for running tasks in series

or you can see the documentation npm

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