“Task function must be specified at Gulp.set” error when running gulp

蓝咒 提交于 2019-12-20 06:07:19

问题


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);


来源:https://stackoverflow.com/questions/53881064/task-function-must-be-specified-at-gulp-set-error-when-running-gulp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!