A similar question has been asked previously here:
Error: Task requires a name at Gulp.Orchestrator.add
In my case I was setting up a gulp
build.
Installed
gulp-connect
gulp-postcss
gulp-sourcemaps
when I run gulp
I get
Error
C:\Users\jwilson\Documents\James\jameswilson.co.za\node_modules\orchestrator\index.js:44
throw new Error('Task '+name+' requires a function that is a function');
^
Error: Task default requires a function that is a function
at Gulp.Orchestrator.add (C:\Users\jwilson\Documents\James\jameswilson.co.za\node_modules\orchestrator\index.js:44:10)
at Object.<anonymous> (C:\Users\jwilson\Documents\James\jameswilson.co.za\gulpfile.js:19:6)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Liftoff.handleArguments (C:\Users\jwilson\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:116:3)
Gulpfile
var gulp = require('gulp'),
connect = require('gulp-connect');
postcss = require('gulp-postcss');
sourcemaps = require('gulp-sourcemaps');
gulp.task('connect', function() {
connect.server();
});
gulp.task('css', function () {
return gulp.src('src/**/*.css')
.pipe( sourcemaps.init() )
.pipe( postcss([ require('precss'), require('autoprefixer') ]) )
.pipe( sourcemaps.write('.') )
.pipe( gulp.dest('build/') );
});
gulp.task('default', ['css'], ['connect']);
I think the error is here:
gulp.task('default', ['css'], ['connect']);
It looks to me as if you are using gulp v3.9.1 or older. In this case, gulp.task
takes up to three arguments: a task name, an array of dependent task names, and a function. You are passing a task name and two 1-element arrays. Gulp is complaining because it was expecting the third argument to task
to be a function but you passed it the array ['connect']
.
I imagine you want to replace the two 1-element arrays with a 2-element array:
gulp.task('default', ['css', 'connect']);
For gulp v4 or later, you can run the two tasks in series using the following:
gulp.task('default', gulp.series('css', 'connect'));
Or in parallel, using:
gulp.task('default', gulp.parallel('css', 'connect'));