gulp报错:The following tasks did not complete: task_name

本文介绍了在执行gulp任务时遇到的未完成错误问题。问题出现在没有正确结束gulp任务。通过分析,发现需要在任务中添加回调函数cb来确保任务的正常结束,并提供了添加异步处理和回调的解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题描述

在如下代码运行时报错:

gulp.task('A' , function(){
   console.log('A') 
});
gulp.task('B' , function(){ //运行B之前先去运行A
   console.log('B')
});

gulp.task('my-task', gulp.series("A","B",function(){
	console.log("AB")
}))

报错如下:

D:\me\gulp\gulp-test>gulp task
[14:36:02] Using gulpfile D:\me\gulp\gulp-test\gulpfile.js
[14:36:02] Starting 'task'...
[14:36:02] Starting 'A'...
A
[14:36:02] The following tasks did not complete: task, A
[14:36:02] Did you forget to signal async completion?

分析问题

在不使用文件流的情况下,向task的函数里传入一个名叫cb的回调函数,以结束task,如下代码所示:

gulp.task('test', cb => {
  console.log('Hello World!');
  cb();
});

解决问题

  • 添加asyncawait异步方法处理:
gulp.task('A' , async function(){
  await console.log('A') 
});
gulp.task('B' , async function(){ 
   await console.log('B')
});

gulp.task('my-task', gulp.series("A","B", async function(){
	await console.log("AB")
}))
  • 添加结束回调done()
gulp.task('A' , function(){
  console.log('A') 
  done()
});
gulp.task('B' , function(done){ 
   console.log('B')
   done()
});

gulp.task('my-task', gulp.series("A","B", function(done){
	console.log("AB")
	done()
}))
  • 最终打印结果
[15:00:29] Using gulpfile D:\me\gulp\gulp-test\gulpfile.js
[15:00:29] Starting 'my-task'...
[15:00:29] Starting 'A'...
A
[15:00:29] Finished 'A' after 7.08 ms
[15:00:29] Starting 'B'...
B
[15:00:29] Finished 'B' after 2.26 ms
[15:00:29] Starting '<anonymous>'...
AB
[15:00:29] Finished '<anonymous>' after 2.02 ms
[15:00:29] Finished 'my-task' after 20 ms
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我的小英短

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值