Leigh277
Leigh277

Reputation: 191

Gulp Scripts Throw Error: throw new errors.AssertionError

Assertion Error using Gulp:

$ gulp scripts
  assert.js:42
   throw new errors.AssertionError({
   ^
AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (/Users/ThedWord/Documents/my-project/node_modules/undertaker/lib/set-task.js:10:3)
    at Gulp.task (/Users/ThedWord/Documents/my-proje
ct/node_modules/undertaker/lib/task.js:13:8)
    at Object.<anonymous> (/Users/ThedWord/Documents/my-project/gulpfile.js:10:6)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:    
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Module.require (module.js:604:17)
    at require (internal/module.js:11:18)
/*eslint-env node */
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync').create();
const eslint = require('gulp-eslint');
const jasmine = require('gulp-jasmine-phantom');
const concat = require('gulp-concat');

gulp.task('default', ['copy-html', 'copy-images', 'styles', 'lint'], function() {
    gulp.watch('sass/**/*.scss', ['styles']);
    gulp.watch('js/**/*.js', ['lint']);
  gulp.watch('/index.html', ['copy-html']);
  gulp.watch('./build/index.html').on('change', browserSync.reload);
});

  browserSync.init({
        server: './dist'
    });


 gulp.task('scripts', function(){
    gulp.src('js/**/*.js')
      .pipe(concat('all.js'))
      .pipe(gulp.dest('dist/js'));
 });

 gulp.task('scripts-dist', function(){
   gulp.src('js/**/*.js')
      .pipe(concat('all.js'))
      .pipe(gulp.dest('dist/js'));
 });


gulp.task('copy-html', function() {
  gulp.src('./index.html')
      .pipe(gulp.dest('./dist'));
});

gulp.task('copy-images', function(){
  gulp.src('img/*')
      .pipe(gulp.dest('dist/img'));
});

gulp.task('styles', function() {
    gulp.src('sass/**/*.scss')
        .pipe(sass().on('error', sass.logError))
        .pipe(autoprefixer({
            browsers: ['last 2 versions']
        }))
        .pipe(gulp.dest('dist/css'))
        .pipe(browserSync.stream());


 });

    gulp.task('lint', function () {
        return gulp.src(['js/**/*.js'])
            // eslint() attaches the lint output to the eslint property
            // of the file object so it can be used by other modules.
            .pipe(eslint())
            // eslint.format() outputs the lint results to the console.
            // Alternatively use eslint.formatEach() (see Docs).
            .pipe(eslint.format())
            // To have the process exit with an error code (1) on
            // lint error, return the stream and pipe to failOnError last.
            .pipe(eslint.failOnError());
    });

    gulp.task('dist', [
        'copy-html',
        'copy-images',
        'styles',
        'lint',
        'scripts-dist'
    ]);

    gulp.task('tests', function () {
        gulp.src('tests/spec/extraSpec.js')
            .pipe(jasmine({
                integration: true,
                vendor: 'js/**/*.js'
            }));
    });

Upvotes: 0

Views: 1440

Answers (1)

justinhartman
justinhartman

Reputation: 722

The problem you are encountering is that you are running gulp v4.0 using gulp 3 syntax. The AssertionError: Task function must be specified error comes from the fact that gulp.task has changed and the 3 parameters signature was removed. In short, your task below will need to be changed to remove the [] parameter:

gulp.task('default', ['copy-html', 'copy-images', 'styles', 'lint'], function() {
    gulp.watch('sass/**/*.scss', ['styles']);
    gulp.watch('js/**/*.js', ['lint']);
  gulp.watch('/index.html', ['copy-html']);
  gulp.watch('./build/index.html').on('change', browserSync.reload);
});

This article will help you migrate to gulp 4 syntax.

If you'd like a simple fix to your problem, without having to make changes to your gulpfile.js, run the following command to downgrade your version of gulp from version 4 to 3.9.1:

npm install [email protected] --save

Assuming all goes well you should no longer see the Assertion error.

Upvotes: 3

Related Questions