How to Fix AssertionError [ERR_ASSERTION]: Task Function Must Be Specified

AssertionError [ERR_ASSERTION]: Task Function Must Be Specified error occurs in JavaScript because starting from Gulp.js version 4, the “list parameter has been deprecated.”

Overview of error and solution

Visual Representation of AssertionError [ERR_ASSERTION] Task Function Must Be Specified

How to fix the error?

To fix the Task Function Must Be Specified error,  use the “gulp.series() and gulp.parallel()” functions. These functions allow a more explicit and readable way to define the order and concurrency of task execution.

gulp.series()

The gulp.series() function runs the provided tasks sequentially, one after the other:

gulp.task('default', gulp.series('task1', 'task2', function(done) {
  // 'task1' would run first, then 'task2', and then this function
  done();
}));

gulp.parallel()

The gulp.parallel() function runs the provided tasks concurrently, all at the same time.

gulp.task('default', gulp.parallel('task1', 'task2', function(done) {
  // 'task1', 'task2', and this function would all start at the same time
  done();
}));

You can also mix and match gulp.series() and gulp.parallel() to create more complex task execution patterns:

gulp.task('default', gulp.series('task1', gulp.parallel('task2', 'task3'), 'task4'));

In this code example:

  1. The task1 will run first.
  2. Once task1 has been completed, task2 and task3 will run in parallel.
  3. After both task2 and task3 have been completed, task4 will run.

If migrating from Gulp 3 to Gulp 4, you must refactor your task definitions to use these new functions.