Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp: Task function must be specified at Gulp.set

When I try to run gulp I get the title error.

My gulpfile.js:

    var gulp = require('gulp'),
        connect = require('gulp-connect-php'),
        gulpPhpunit = require('gulp-phpunit');

    gulp.task('gulpPhpunit', function() {
      var options = {debug: false};
      gulp.src('phpunit.xml') 
    .pipe(phpunit('./vendor/bin/phpunit',options));
    });

    gulp.task("default", ["gulpPhpunit"]);

The error

    // error
    assert.js:42
      throw new errors.AssertionError({
      ^

    AssertionError [ERR_ASSERTION]: Task function must be specified
        at Gulp.set [as _setTask] (/var/www/html/wptest2/node_modules/undertaker/lib/set-task.js:10:3)
        at Gulp.task (/var/www/html/wptest2/node_modules/undertaker/lib/task.js:13:8)
        at Object.<anonymous> (/var/www/html/wptest2/gulpfile.js:26:6)
        at Module._compile (module.js:652:30)
        at Object.Module._extensions..js (module.js:663:10)
        at Module.load (module.js:565:32)
        at tryModuleLoad (module.js:505:12)
        at Function.Module._load (module.js:497:3)
        at Module.require (module.js:596:17)
        at require (internal/module.js:11:18)

"Task function must be specified", am I not pointing to gulpPhpunit correctly? The code was copied out of the docs (example 2).

like image 980
Sean D Avatar asked Mar 21 '19 13:03

Sean D


People also ask

How do you define a task in Gulp?

gulp. task('task-name', function() { // Stuff here }); task-name refers to the name of the task, which would be used whenever you want to run a task in Gulp. You can also run the same task in the command line by writing gulp task-name .

How do I run gulp locally?

To install Gulp locally, navigate to your project directory and run npm install gulp . You can save it to your package. json dependencies by running npm install gulp --save-dev . Once you have Gulp installed locally, you can then proceed to create your gulpfile.

What is Gulp SRC?

src() is given a glob to read from the file system and produces a Node stream. It locates all matching files and reads them into memory to pass through the stream. The stream produced by src() should be returned from a task to signal async completion, as mentioned in Creating Tasks.


1 Answers

If you use gulp v4, the syntax has changed. You can downgrade your gulp version or change some parts of your code to run with the new gulp version:

var gulp = require('gulp'),
    connect = require('gulp-connect-php'),
    gulpPhpunit = require('gulp-phpunit');

gulp.task('gulpPhpunit', function (done) {
    // var options = {debug: false};
    gulp.src('phpunit.xml')
        .pipe(phpunit('./vendor/bin/phpunit', options));

    done();
});

gulp.task("default", gulp.series('gulpPhpunit'));

The changes are the done callback and the gulp.series() part.

See running tasks in series

like image 174
d-h-e Avatar answered Oct 11 '22 22:10

d-h-e