Error in executing Gulp tasks (task)

Asked

Viewed 133 times

1

Could someone help me with this mistake? I am running the command "Gulp" in cmd and this message appears:

AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Users\2018-0137\Downloads\gentelella-master\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Users\2018-0137\Downloads\gentelella-master\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Users\2018-0137\Downloads\gentelella-master\gulpfile.js:60: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:22:18)

It also follows the code of the aquivo gulpfile.js:

var gulp = require('gulp'),
    concat = require('gulp-concat'),
    uglify = require('gulp-uglify'),
    rename = require('gulp-rename'),
    sass = require('gulp-sass'),
    autoprefixer = require('gulp-autoprefixer'),
    browserSync = require('browser-sync').create();

var DEST = 'build/';

gulp.task('scripts', function() {
    return gulp.src([
        'src/js/helpers/*.js',
        'src/js/*.js',
      ])
      .pipe(concat('custom.js'))
      .pipe(gulp.dest(DEST+'/js'))
      .pipe(rename({suffix: '.min'}))
      .pipe(uglify())
      .pipe(gulp.dest(DEST+'/js'))
      .pipe(browserSync.stream());
});

var compileSASS = function (filename, options) {
  return sass('src/scss/*.scss', options)
        .pipe(autoprefixer('last 2 versions', '> 5%'))
        .pipe(concat(filename))
        .pipe(gulp.dest(DEST+'/css'))
        .pipe(browserSync.stream());
};

gulp.task('sass', function() {
    return compileSASS('custom.css', {});
});

gulp.task('sass-minify', function() {
    return compileSASS('custom.min.css', {style: 'compressed'});
});

gulp.task('browser-sync', function() {
    browserSync.init({
        server: {
            baseDir: './'
        },
        startPath: './production/index.html'
    });
});

gulp.task('watch', function() {
  gulp.watch('production/*.html', browserSync.reload);
  gulp.watch('src/js/*.js', ['scripts']);
  gulp.watch('src/scss/*.scss', ['sass', 'sass-minify']);
});

gulp.task('default', ['browser-sync', 'watch']);

package.json file

{
  "name": "Admin",
  "version": "1.1.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "css",
    "js",
    "html",
    "template",
    "admin",
    "bootstrap",
    "theme",
    "backend",
    "responsive"
  ],
  "author": "Saulo Lago",
  "devDependencies": {
    "browser-sync": "*",
    "gulp": "*",
    "gulp-autoprefixer": "*",
    "gulp-concat": "*",
    "gulp-rename": "*",
    "gulp-sass": "*",
    "gulp-uglify": "*"
  }
}

Thank you guys. I’m on hold.

  • Try running the command on a Unix terminal, such as Git bash

  • @Ikarosales on Windows?

  • Yesim :) That’s right

1 answer

0

The reason for the error must be the version of your Gulp. Instead of

gulp.task('default', ['browser-sync', 'watch']);

Try it this way

 gulp.task('default', gulp.series('browser-sync', 'watch'));

Probably this guy can give error tbm

 gulp.task('watch', function() {
   gulp.watch('production/*.html', browserSync.reload);
   gulp.watch('src/js/*.js', ['scripts']);
   gulp.watch('src/scss/*.scss', ['sass', 'sass-minify']);
 });

Then you can use the same command above Gulp.series(), like this:

gulp.task('watch', function() {
   gulp.watch('production/*.html', browserSync.reload);
   gulp.watch('src/js/*.js', gulp.series('scripts'));
   gulp.watch('src/scss/*.scss', gulp.series('sass', 'sass-minify'));
 });

Browser other questions tagged

You are not signed in. Login or sign up in order to post.