Search code examples
node.jsgulphyperledger-fabric

how to fix "Task 'test' is not in your gulpfile" error when using gulpfile


/*
# Copyright IBM Corp. All Rights Reserved.
#
# SPDX-License-Identifier: Apache-2.0
*/
const requireDir = require('require-dir');
const gulp = require('gulp');

// Require all tasks in gulp/tasks, including subfolders
requireDir('./build/tasks', {recurse: true});

gulp.task('default', ['lint', 'check_license'], () => {
	// This will only run if the lint task is successful...
});

screen shot of the error I'm new in the hyperledger community, I tried to test fabric-sdk-node project that I cloned from github. When I try 'gulp test' it hsows me an error "Task 'test' is not in your gulpfile". how can I solve it ? this is my gulpfile.js


Solution

  • I played around with that require-dir package for awhile. The only way I could get it to work was:

    // in './build/tasks/test.js'
    
    const gulp = require('gulp');
    const sass = require('gulp-sass');
    
    // note the use of gulp.task syntax, **not** function test()
    
    gulp.task('test', function() {
      console.log("in test task");
      return gulp.src('./scss/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./dist'));
    });
    

    // in 'gulpfile.js'
    
    const requireDir = require('require-dir');
    const gulp = require('gulp');
    
    // Require all tasks in gulp/tasks, including subfolders
    requireDir('./build/tasks', { recurse: true });
    
    gulp.task('default', gulp.series('test'));  // note I have gulp v4 on my machine
    

    This does run the test task successfully, transpiling the scss file in this case.

    Despite the fact that I am running gulp4 I had to use the gulp.task('test') syntax to get it to work. It would not work if the test task was defined like so:

    function test() {
      console.log("in test function");
    
      return gulp.src('./scss/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('./dist'));
    };
    

    which I would normally use. (With gulp.task('default', gulp.series(test));)

    Are your tasks created as gulp.task('sdfsdfsdfs')? I assume they are since you are using the gulp.task('default', ['lint', 'check_license'] type of syntax.