Failed to list gulp tasks in WebStorm 2016.1

2019-09-15 19:49发布

问题:

I am using Gulp 3.9.1, node 5.7.1, npm 3.10.3, and WebStorm 2016.1. When I try to setup gulp for my project, I get the following error:

/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

And when I force to rescan tasks:

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

When I execute gulp --help at CLI:

$ 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

It's almost as if WebStorm is tacking on extra params, but the version of gulp I have doesn't support said params.

Updated:

I ran the following to installed gulp-cli (the second from my project root):

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

If I do gulp --help I get the right options:

$ 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 returns the path /Users/me/Developer/homebrew/bin/gulp. But if I run gulp --color I still get the error error: unknown option--color'`

If I do the same experiment using the gulp path of ~/Developer/workspace/project/node_modules/gulp-cli/bin/gulp.js --help(again, from CLI) I get the exact same results: --help outputs the correct options, but --color and --no-color fails with the same error, despite being listed as valid options.

回答1:

I ran into this same issue just now. I tracked it down to a part of our app creating a custom CLI using commander.js. I was able to tell commander to pass along the options needed. I will have to send a pull request over instead of hacking up the node_modules version.

project gulpfile.js:

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

Project\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');