Gulp 4: Functions that return gulp.series or gulp.parallel do not allow tasks to complete
See original GitHub issueWhat were you expecting to happen?
I wrote up this gulp 4 code:
//reloads the browser
function reload(done){
browserSync.reload();
done();
}
//If running in PHP mode, convert the html files to php files before reloading
gulp.task('pug:reload', (done)=>{
if (config.serve === 'php'){
return gulp.series('convert-HTML', reload);
} else {
return gulp.series(reload);
}
});
//The main pug task
gulp.task('pug', gulp.series(
'pug:compile',
'pug:reload',//the one causing the issue
));
When running in PHP mode, I expected that the main pug task would essentially equate to this:
gulp.task('pug', gulp.series(
'pug:compile',
gulp.series('convert-HTML', reload),
));
When running in HTML mode, I expected that the main pug task would essentially equate to this:
gulp.task('pug', gulp.series(
'pug:compile',
gulp.series(reload),
));
I tested putting the code inline like that just to make sure that the tasks weren’t broken. It did indeed work as expected.
What actually happened?
When I tried to run the ‘pug:reload’ task, it came up with this error:
[00:45:34] The following tasks did not complete: pug:reload
[00:45:34] Did you forget to signal async completion?
The only way I could get around this was to do this with my code:
var pugReload = gulp.series(reload);
if (config.serve === 'php') pugReload = gulp.series('convert-HTML', reload);
gulp.task('pug', gulp.series(
'pug:compile',
pugReload,
));
It was then able to compile successfully.
What version of gulp are you using?
[01:10:37] CLI version 1.2.2
[01:10:37] Local version 4.0.0-alpha.2
What versions of npm and node are you using?
npm: 3.10.6 node: 4.4.7
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:18 (7 by maintainers)
Top Results From Across the Web
series() - gulp.js
series ()#. Combines task functions and/or composed operations into larger operations that will be executed one after another, in sequential order.
Read more >The new task execution system - gulp.parallel and gulp.series
One of the major changes in Gulp 4 is the new task execution system. ... gulp.parallel and gulp.series are functions, and accept functions....
Read more >Gulp 4 tasks not running synchronously with parallel/series
You have return statements inside your task, before even task completes. For example you should change your task function compress(callback) ...
Read more >Construct Gulp Series Tasks Dynamically - Medium
Takes a number of task names or functions and returns a function of the composed tasks or functions. When using task names, the...
Read more >02 - Introduction to Gulp.js series and parallel tasks - Gulp 4
Gulpjs series where I go over the basic content:⦾ intro ⦾ gulp tasks ( series & parallel )⦾ compiling SCSS⦾ cleaning/minifying CSS⦾ ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This should really be explained better in the docs, I’ve just spent a couple of hours trying to figure out how to run a basic gulp setup…
Had I not found this issue, I’d pull all of my hair out
Ahh ok, I get it now. Thanks for the help 😃
I had a thought though. Since the main reason that the task fails is because the return function isn’t being called, I thought I would try calling it from the return statement.
Using this syntax works 😃