JavaEar 专注于收集分享传播有价值的技术资料

Gulp and run-sequence error : Task is not configured as a task on gulp

I'm trying to add run-sequence to my gulp workflow but I have this error every time I try to execute my task in which I use run-sequence :

Task is not configured as a task on gulp.

According to the source of run-sequence, this is caused by this test :

if (isTask && !gulp.hasTask(t)) {
    throw new Error("Task "+t+" is not configured as a task on gulp.");
}

My tasks are splitted into multiple file, and everything works fine if I execute a single task or a task with a dependence, the only error I have is on this one :

'use strict';

var gulp = require('gulp'),
    runSequence = require('run-sequence');

module.exports = gulp.task('default', function() {
    if (release) {
        runSequence(
            'clean',
            ['index', 'styles', 'images', 'fonts', 'templates'],
            'browserify',
            'minify'
        );
    } else {
        runSequence(
            'clean',
            ['index', 'styles', 'images', 'fonts', 'templates'],
            ['watchify', 'watch']
        );
    }
});

The test shouldn't fail, because when I try to add this piece of code just before my runSequence function, it's output true for every task I try to execute in the function :

console.log(gulp.hasTask('clean'); // Output true
runSequence(
    'clean',
    ['index', 'styles', 'images', 'fonts', 'templates'],
    ['watchify', 'watch']
);

But I still have the error : Task clean is not configured as a task on gulp. Same if I remove 'clean' from the array, it will fail on the next task : Task index is not configured as a task on gulp.

If anybody have an idea about what's going on here...

Thanks for the help.

4个回答

    最佳答案
  1. I had this same problem and my solution was to do this instead in my require statement as Jacob Thomason mentioned.

    var runSequence = require('run-sequence').use(gulp);
    
  2. 参考答案2
  3. Is your run-sequence installed globally or locally?

    Try installing it locally, that solved problem for me!

    npm install run-sequence
    
  4. 参考答案3
  5. The issue is that run-sequence does a bad job of constructing itself with dependencies. As gulp is a dependency, it should be taking that into the constructor as an argument, which you would need to supply. Unfortunately, the way it's written, it's difficult to do this. There is a .use() method that you can chain to the require() statement for the module, to define the gulp module, but even this is wishful thinking, assuming that the bootstrapping for the require statement is being done where the gulp module is available.

    I've just done a rewrite on it. It's not BC with the current version, as the API has changed a little. You need to construct the module assigning it to a variable and call the run() method, passing in the tasks and options as described in the current docs.

    You can check it out here...

    https://github.com/oojacoboo/run-sequence

    If people want, I can update the README, possibly give it another non-conflicting name and clean some things up. I realize that the rewrite might have diverged more than some prefer, but dependencies can at least be properly handled now.

  6. 参考答案4