欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

运行gulp项目报错:AssertionError: Task function must be specified。

发布时间:2025/5/22 编程问答 43 豆豆
生活随笔 收集整理的这篇文章主要介绍了 运行gulp项目报错:AssertionError: Task function must be specified。 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

gulp 3 和 gulp 4运行方式是不一样的,所以会出现错误。具体细节,可以看这里

gup3 VS gulp4 区别

Gulp 4最大的变化就是你不能像以前那样传递一个依赖任务列表。

Gulp3,如果有一个任务A,B和C的列表,你想在一个序列中运行(确保A在B开始之前完成,而B在C开始之前完成),代码如下:

gulp.task('a', function () {// Do something. }); gulp.task('b', ['a'], function () {// Do some stuff. }); gulp.task('c', ['b'], function () {// Do some more stuff. });

在Gulp 4中,你不能再这样做了。你会得到以下错误:

assert.js:85throw new assert.AssertionError({^ AssertionError: Task function must be specifiedat Gulp.set [as _setTask] (/home/hope/web/node_modules/undertaker/lib/set-task.js:10:3)at Gulp.task (/home/hope/web/node_modules/undertaker/lib/task.js:13:8)at Object.<anonymous> (/home/hope/web/gulpfile.js:31:6)at Module._compile (module.js:570:32)at Object.Module._extensions..js (module.js:579:10)at Module.load (module.js:487:32)at tryModuleLoad (module.js:446:12)at Function.Module._load (module.js:438:3)at Module.require (module.js:497:17)at require (internal/module.js:20:19)

不要用Gulp3的方式指定依赖任务,你需要使用gulp.seriesgulp.parallel,因为gulp任务现在只有两个参数。

gulp.series:按照顺序执行
gulp.paralle:可以并行计算

gulp.task('my-tasks', gulp.series('a', 'b', 'c', function() {// Do something after a, b, and c are finished. })); gulp.task('build', gulp.parallel('styles', 'scripts', 'images', function () {// Build the website. }));

或者这样

gulp.task('my-tasks', gulp.series('a', gulp.parallel('styles','scripts', 'images'), 'b', 'c', function() {// Do something after a, b, and c are finished. }));

相关任务必须在被调用之前发生。

参考:
https://github.com/gulpjs/gulp/blob/master/docs/API.md
https://www.fastless.com/gulp-4
https://www.jianshu.com/p/40b99bed3127

转载于:https://my.oschina.net/jack088/blog/3057999

《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读

总结

以上是生活随笔为你收集整理的运行gulp项目报错:AssertionError: Task function must be specified。的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。