asynchronousgulpcompletiongulp-4

Light Gulp 4 task still throwing 'async completion' error


I've not used Gulp before, so I'm not migrating an old gulpfile to Gulp 4. I'm just trying to get a few basic tasks set up. However, regardless of the method I use to signal async completion as well documented in this post I still get the "Did you forget to signal async completion?" error.

'use strict';

/*
=====
PLUGINS
=====
*/

var gulp = require('gulp'),
    plumber = require('gulp-plumber');

// sass
var sass = require('gulp-sass');
sass.compiler = require('node-sass');

// js
var concat = require('gulp-concat'),
    uglify = require('gulp-uglify');


/*
=====
TASKS
=====
*/

gulp.task('sass', function() {
    return gulp.src('./lib/**/*.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('./lib/build'))
})

/*
=====
EXPORT TASKS
=====
*/

exports.sass = sass;

With this super barebones setup shouldn't it work? Doesn't return gulp.src return a stream? What am I missing?

Node 10.15.0, Gulp CLI 2.2.0, Gulp 4.0.1


Solution

  • Try

    // exports.sass = sass;
    
    exports.sass = gulp.series('sass');
    

    or

    exports.sass = 'sass';
    

    You are using the task version (gulp.task) so you need the quotes.

    If you were using the function version (recommended):

    function sass2 () {
      return gulp.src('./lib/**/*.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(gulp.dest('./lib/build'))
    };
    

    then

    exports.sass = sass2;
    

    works fine. Note that you have a var sass already so you would have to name your function sass2 to something other than just sass again of course.