【问题标题】:Failed to list gulp tasks in WebStorm 2016.1无法在 WebStorm 2016.1 中列出 gulp 任务
【发布时间】:2016-11-16 08:16:40
【问题描述】:

我正在使用 Gulp 3.9.1、节点 5.7.1、npm 3.10.3 和 WebStorm 2016.1。当我尝试为我的项目设置 gulp 时,我收到以下错误:

/usr/local/bin/node /Users/msbauer/Developer/workspaces/provider-data-management/node_modules/gulp/bin/gulp.js --color --gulpfile /Users/msbauer/Developer/workspaces/provider-data-management/gulpfile.js

  error: unknown option `--color'


Process finished with exit code 1

当我强制重新扫描任务时:

Failed to list gulp tasks in provider-data-management/gulpfile.js: process finished with exit code 1 (a non-zero exit code means an error)
 * Edit settings

$ /usr/local/bin/node /Users/msbauer/Developer/workspaces/provider-data-management/node_modules/gulp/bin/gulp.js --no-color --gulpfile /Users/msbauer/Developer/workspaces/provider-data-management/gulpfile.js --tasks

  error: unknown option `--no-color'


Process finished with exit code 1

当我在 CLI 中执行 gulp --help 时:

$ gulp --help

  Usage: gulp [options] [command]


  Commands:

    about   display version information about availity-workflow project
    init    initialize project metadata: package.json, bower.json, availity.json and README.md

  Options:

    -h, --help     output usage information
    -V, --version  output the version number

就好像 WebStorm 正在添加额外的参数,但我拥有的 gulp 版本不支持所述参数。

更新:

我运行以下命令来安装 gulp-cli(我的项目根目录中的第二个):

$ brew install gulp-cli
$ npm install -g gulp-cli

如果我选择gulp --help,我会得到正确的选择:

$ gulp --help

Usage: gulp [options] tasks

Options:
  --help, -h       Show this help.                                     [boolean]
  --version, -v    Print the global and local gulp versions.           [boolean]
  --require        Will require a module before running the gulpfile. This is
                   useful for transpilers but also has other applications.
                                                                        [string]
  --gulpfile       Manually set path of gulpfile. Useful if you have multiple
                   gulpfiles. This will set the CWD to the gulpfile directory as
                   well.                                                [string]
  --cwd            Manually set the CWD. The search for the gulpfile, as well as
                   the relativity of all requires will be from here.    [string]
  --verify         Will verify plugins referenced in project's package.json
                   against the plugins blacklist.
  --tasks, -T      Print the task dependency tree for the loaded gulpfile.
                                                                       [boolean]
  --depth          Specify the depth of the task dependency tree.
  --tasks-simple   Print a plaintext list of tasks for the loaded gulpfile.
                                                                       [boolean]
  --tasks-json     Print the task dependency tree, in JSON format, for the
                   loaded gulpfile.
  --color          Will force gulp and gulp plugins to display colors, even when
                   no color support is detected.                       [boolean]
  --no-color       Will force gulp and gulp plugins to not display colors, even
                   when color support is detected.                     [boolean]
  --silent, -S     Suppress all gulp logging.                          [boolean]
  --continue       Continue execution of tasks upon failure.           [boolean]
  --log-level, -L  Set the loglevel. -L for least verbose and -LLLL for most
                   verbose. -LLL is default.                             [count]

which 返回路径 /Users/me/Developer/homebrew/bin/gulp。但是如果我运行gulp --color,我仍然会收到错误error: unknown option--color'`

如果我使用 ~/Developer/workspace/project/node_modules/gulp-cli/bin/gulp.js --help 的 gulp 路径(同样,来自 CLI)进行相同的实验,我会得到完全相同的结果:--help 输出正确的选项,但 --color--no-color 以相同的方式失败错误,尽管被列为有效选项。

【问题讨论】:

  • 我自己并不是真正的 gulp 用户(还 - 刚刚开始学习/使用它).. 但我已经安装了 gulp-cli(全球;根据 official documentation)它是 v1 .2.1(最新版本)。如果我这样做gulp --help .. 我确实看到了不同的输出,其中--color 选项受支持。我相信您的 gulp 只是 gulp 本身,而您还需要 gulp-cli (这就是 IDE 必须用来运行 gulp 任务的东西)。 P.S. 节点 4.4.4; npm 2.15.1(捆绑一个)。
  • 就是这样!将此添加为答案,我会接受。
  • 我收回了。当我从 CLI 执行 --help 时,它添加了选项,但如果我真的尝试从 CLI 或 WebStorm 运行它,我仍然会收到相同的错误
  • 所以它一定是调用错误gulp.js - 看看你是否可以在那里指定正确的路径。顺便说一句——在那之后你有没有尝试过重新启动 IDE?它可能仍然只是使用旧的(旧的 PATH)。也可以尝试全新的项目(尽可能完成最简单的任务——看看结果如何)。
  • P.S.您还可以升级到最新的稳定版 WebStorm 2016.2(昨天或前一天发布)。也许它会在没有--color 选项的情况下执行不同的命令?

标签: javascript node.js gulp webstorm


【解决方案1】:

我刚才遇到了同样的问题。我追踪到了我们应用程序的一部分,它使用commander.js 创建了一个自定义CLI。我能够告诉指挥官传递所需的选项。我将不得不发送一个拉取请求而不是破解 node_modules 版本。

项目 gulpfile.js:

var cli = require('custom-cli');

项目\node_modules\custom-cli\cli\index.js

var program = require('commander');

program.version(manifests.package.json.version);

//WebStorm needs to pass these options to gulp, so commander has to know about them
program.option('--no-color', 'Disable Colors');
program.option('--gulpfile', 'gulpfile');

【讨论】:

    猜你喜欢
    • 2015-12-25
    • 2017-08-08
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 2016-04-01
    • 2016-11-08
    • 1970-01-01
    • 2018-08-22
    相关资源
    最近更新 更多