您的位置:首页 > 其它

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

2019-05-13 15:05 781 查看

问题描述

在如下代码运行时报错:

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

解决问题

  • 添加
    async
    await
    异步方法处理:
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐