背景
学习gulp的前端自动化构建,按照示例代码,跑了一个简单的task,控制台打出如下提示:
The following tasks did not complete: testGulp
Did you forget to signal async completion?
查阅Stack Overflow,表示有五种解决办法,在这里提供一种更简单的改法。
问题重现
原代码:
1 const gulp = require(‘gulp‘); 2 gulp.task(‘testGulp‘, () => { 3 console.log(‘Hello World!‘); 4 });
控制台报错:
The following tasks did not complete: testGulp
Did you forget to signal async completion?
解决方法,使用 async 和 await。
修改后代码
1 const gulp = require(‘gulp‘); 2 gulp.task(‘script‘, async() => { 3 await console.log(‘Hello World!‘); 4 });
控制台输出正常
1 $ gulp script 2 [16:29:06] Using gulpfile D:\workspace\my-project\gulpfile.js 3 [16:29:06] Starting ‘script‘... 4 [16:29:06] Finished ‘script‘ after 8.84 ms
附官方方法
在不使用文件流的情况下,向task的函数里传入一个名叫done的回调函数,以结束task,如下代码所示:
1 gulp.task(‘testGulp‘, done => { 2 console.log(‘Hello World!‘); 3 done(); 4 });
done回调函数的作用是在task完成时通知Gulp(而不是返回一个流),而task里的所有其他功能都纯粹依赖Node来实现。
————————————————
版权声明:本文为CSDN博主「奋斗的小绿萝」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_40817115/article/details/81079507
gulp: Did you forget to signal async completion?处理新思路
原文:https://www.cnblogs.com/chunboli/p/14760400.html