【问题标题】:how to fix "Task 'test' is not in your gulpfile" error when using gulpfile使用gulpfile时如何修复“任务'test'不在你的gulpfile中”错误
【发布时间】:2019-05-10 11:39:06
【问题描述】:

/*
# 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 我是超级账本社区的新手,我尝试测试从 github 克隆的 fabric-sdk-node 项目。当我尝试“gulp test”时,它告诉我一个错误“任务'test'不在你的 gulpfile 中”。 我该如何解决? 这是我的 gulpfile.js

【问题讨论】:

  • 你必须展示你的 gulpfile.js。它显然在 npt 中有一个名为 test 的任务。
  • 没错,它不包含测试任务,但文件夹 /build/tasks 包含一个 test.js

标签: node.js gulp hyperledger-fabric


【解决方案1】:

我玩了一会儿require-dir 包。我可以让它工作的唯一方法是:

// 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

这确实成功运行了test 任务,在这种情况下转换了scss 文件。

尽管我正在运行 gulp4,但我必须使用 gulp.task('test') 语法才能使其工作。如果test 任务是这样定义的,它将不起作用:

function test() {
  console.log("in test function");

  return gulp.src('./scss/*.scss')
    .pipe(sass())
    .pipe(gulp.dest('./dist'));
};

我通常会使用。 (与gulp.task('default', gulp.series(test));

您的任务是否创建为gulp.task('sdfsdfsdfs')?我认为它们是因为您使用的是 gulp.task('default', ['lint', 'check_license'] 类型的语法。

【讨论】:

  • 太好了,别忘了接受答案 - 点击答案旁边向上/向下箭头正下方的复选标记。
猜你喜欢
  • 2015-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-13
  • 1970-01-01
  • 1970-01-01
  • 2017-05-10
相关资源
最近更新 更多