“Task function must be specified at Gulp.set” erro

2020-05-09 11:37发布

问题:

I always have the same error when installing gulp:

C:\Users\Thomas\Desktop\Sites CT Graphics\colpaertmarc.be>gulp
assert.js:350
throw err;
^

AssertionError [ERR_ASSERTION]: Task function must be specified at Gulp.set [as _setTask] (C:\Users\Thomas\Desktop\Sites CT Graphics\colpaertmarc.be\node_modules\undertaker\lib\set-task.js:10:3) at Gulp.task (C:\Users\Thomas\Desktop\Sites CT Graphics\colpaertmarc.be\node_modules\undertaker\lib\task.js:13:8) at Object. (C:\Users\Thomas\Desktop\Sites CT Graphics\colpaertmarc.be\gulpfile.js:19:6) at Module._compile (internal/modules/cjs/loader.js:689:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10) at Module.load (internal/modules/cjs/loader.js:599:32) at tryModuleLoad (internal/modules/cjs/loader.js:538:12) at Function.Module._load (internal/modules/cjs/loader.js:530:3) at Module.require (internal/modules/cjs/loader.js:637:17) at require (internal/modules/cjs/helpers.js:22:18)

回答1:

It seems to be related to the Gulp V4, there's two options:

  • Update your code to V4 (Article related )

OR

  • Downgrade gulp version

To downgrade you need to update your package.json with

"gulp": "^3.9.1",

And then remove node_module folder and reinstall npm packages

rm -rf node_modules
npm install


回答2:

This error occurs after you upgrade your gulp version from 3.* to 4.*. If you don't want to downgrade gulp, then you will have to rewrite gulp tasks to be valid with v4 api. Here is example how to rewrite simple gulp task from api notation used in v3 to notation compatiable with v4.

Gulp v3

var gulp = require('gulp');

// Deleting resources task
gulp.task('clearResources', function() {
  console.log('Deleting resources');
});

// Default gulp task
gulp.task('default', ['clearResources'], function() {
  console.log('Running default task');
});

Gulp v4

var gulp = require('gulp');

// Delete resources function
function clearResources() {
  console.log('Deleting resources');
};

// Gulp task(s)
exports.clear = clearResources;
exports.default = gulp.series(clearResources);


回答3:

GULP 4

const { series, parallel } = require('gulp');

gulp.task('clear', gulp.series( async function(){
  // your code
}));

gulp.task('build', gulp.series( async function(){
  // Your code
}));

gulp.task('watch', function(){
  gulp.watch('./javascripts/**/*.js', gulp.series('clear','build'));
});

gulp.task('default', gulp.series('clear','build','watch'));

When I had upgraded the gulp version from ^3.9.1 to ^4.0.2, It worked. Maybe, this code will help you.



标签: gulp