Search code examples
gulpgulp-4

GulpJS 4.0.2 series inside a function called by a series does not work


I have a problem with this code as the second function is never called:

// gulpfile.js
const {series} = require('gulp');

function second(cb){
    console.log('second function');
    cb();
}

function first(cb) {
    console.log('first function');
    series(second);
    cb();
}

exports.default = series(first);

This is the result:

[00:21:56] Starting 'default'...
[00:21:56] Starting 'first'...
first function
[00:21:56] Finished 'first' after 1.99 ms
[00:21:56] Finished 'default' after 5.2 ms

I am using gulp 4.0.2.

In reality I have the second function registered as a task in a different file and that is calling another task and so on. This model was working fine in gulp 3 from where I try to migrate.

I tried async/await with no luck.

Is there any explanation for this? Or how to rewrite the code to work preserving the modularity? Thanks


Solution

  • It looks like the second series should be a const instead of a function according to this page https://gulpjs.com/docs/en/getting-started/creating-tasks/

    So I changed function first() to a const and it works:

    // function first(cb) {
    //     console.log('first function');
    //     series(second);
    //     cb();
    // }
    
    const first = series(second);