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

问题描述

在如下代码运行时报错:

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

解决问题

1. 添加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")
}))

2. 添加结束回调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()
}))

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

1planet

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

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

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

打赏作者

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

抵扣说明:

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

余额充值