Problems when updating from gulp 3 to 4: Task function must be specified

1

It was programmed in gulp 3 but when updating it stopped working and now this appears when running the gulp command:

assert.js:348
    throw err;
    ^

AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (C:\Users\alext\Desktop\Platzigram\node_modules\undertaker\lib\set-task.js:10:3)
    at Gulp.task (C:\Users\alext\Desktop\Platzigram\node_modules\undertaker\lib\task.js:13:8)
    at Object.<anonymous> (C:\Users\alext\Desktop\Platzigram\gulpfile.js:31:6)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:20:18)

The version is:

gulp -v
[20:34:05] CLI version 2.0.1
[20:34:05] Local version 4.0.0

My code for gulpfile.js is:

var gulp = require('gulp');
var sass = require('gulp-sass'); 
var rename = require('gulp-rename');
var babel = require('babelify');
var browserify = require('browserify');
var source = require('vinyl-source-stream');

gulp.task('styles', function(){
  gulp
    .src('index.scss')
    .pipe(sass())
    .pipe(rename('app.css'))
    .pipe(gulp.dest('public'));
})

gulp.task('assets', function(){
    gulp
    .src('assets/*')
    .pipe(gulp.dest('public'));
})

gulp.task('scripts', function(){
    browserify('./src/index.js')
    .transform(babel)
    .bundle()
    .pipe(source('index.js'))
    .pipe(rename('app.js'))
    .pipe(gulp.dest('public'));
})

gulp.task('default', ['styles','assets','scripts']);

Before this appeared, everything worked, it was fine but when it was executed it told me that it had 5 vulnerabilities, which when fixing them sent me the error of the beginning.

    
asked by Care Papa Rh 30.11.2018 в 14:56
source

1 answer

1

I had the same problem, it happens that now gulp @ 4 has additional parameters that makes you migrate a bit the syntax of your tasks, but for good is now more orderly. I leave a link [English] with more details: link

Anyway, now you should use the following

let gulp = require('gulp');
let sass = require('gulp-sass');
let rename = require('gulp-rename');

sass.compiler = require('node-sass');

gulp.task('styles', () => {
    return gulp.src('app.scss')
        .pipe(sass())
        .pipe(rename('app.css'))
        .pipe(gulp.dest('public'));
});


gulp.task('assets', () => {
    gulp.src('assets/*')
        .pipe(gulp.dest('public'));
})

gulp.task('watch', () => {
    gulp.watch('app.scss', gulp.series('styles'));
    gulp.watch('asset/*', gulp.series('assets'));
});

gulp.task('default', gulp.parallel('styles', 'assets'));

I hope I helped you

    
answered by 16.12.2018 / 06:55
source