问题
So I have messed up with removing and installing node and npm to install packages without sudo and now I can't use Grunt panel in Webstorm
The message is:
grunt --no-color --gruntfile /Users/max/repos/cb/Gruntfile.js --tasks /Applications/WebStorm.app/plugins/JavaScriptLanguage/grunt_js/tasks _intellij_grunt_tasks_fetcher
Cannot run program "grunt" (in directory "/Users/max/repos/cb"): error=2, No such file or directory
Looks like the grunt command isn't in your system path.
In order to view/run tasks, you need to install Grunt's command line interface globally:
npm install -g grunt-cli
For more information, please see http://gruntjs.com/getting-started
But what is strange than I can run grunt from terminal, even in Webstorm. Screenshot:

Notice that i have grunt-cli
installed.
回答1:
Do you use NVM to manage Node versions? The problem might be caused by the way NVM uses to patch enviornment variables. Usually it places its initialization logic in ~/.bashrc
If WebStorm is launched from Terminal, it inherits Terminal environment (including modified PATH environment variable, added NVM_DIR env var, etc). In that case, there are no problems with loading Grunt tasks, as WebStorm sees correct PATH value.
If WebStorm is lauched from Desktop (not from Terminal), WebStorm sees incorrect PATH value and fails to load Grunt tasks.
If you're using bash as shell, workaround could be the the following: edit your WebStorm launcher and set command to "/bin/bash -l -c "/path/to/webstorm.sh". This command will perform bash login (i.e. reading your .bashrc/.bash_profile files) and after that will run webstorm.sh.
Hope that will help.
回答2:
I have solved this both on Mac and Linux with proper entries in ~/.bash_profile
file.
The explanation
WebStorm is started with:
/bin/bash -l -c "/path/to/webstorm.sh"
The -l
(dash L) option sets bash to login mode. That means bash will read files in order:
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
before running script after -c option.
I have put export PATH
to ~/.bash_profile
and it helped.
If you set PATH
in ~/.bashrc
then it will not work because in login mode this file is not being read.
My Mac's ~/.bash_profile
:
export PATH=/usr/local/bin:$PATH
export NVM_DIR="/Users/citricacid/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
Additional help
This answer helped me with that a lot, too.
https://stackoverflow.com/a/21712034/1949605
回答3:
I had the same problem and I did:
"So first install the grunt cli tools globally:
npm install -g grunt-cli (or possibly sudo npm install -g grunt-cli ).
You can establish that's working by typing grunt --version
Now you can install the current version of Grunt local to your project. So from your project's location...
npm install grunt --save-dev"
You can found more information in:
Node package ( Grunt ) installed but not available
回答4:
I had the same problem. I solved it via creating a symlink in /usr/sbin
and /usr/bin to /usr/local/bin/grunt
.
Hope it will help you.
回答5:
After viewing the answers here, I fixed this issue with this method: http://ify.io/getting-webstorm-external-tools-to-work-on-webstorm-on-osx/
Firstly, close WebStorm if it is currently open. Then add the following entry to the ‘/Applications/Webstorm.app/Contents/Info.plist’ file.
<key>LSEnvironment</key>
<dict>
<key>PATH</key>
<string>[Your Path Value]</string>
</dict>
[Your Path Value]
should be replaced with the value of your system path (assuming, you can already run the relevant command from the terminal… i.e., npm, grunt etc.,). Note that the system path can be retrieved using the following terminal command:
echo $PATH
This command simply retrieves the PATH
value from ~/.MacOSX/environment.plist
.
I didn't do this step and it worked, including it incase it doesn't for you
Now refresh the updated Info.plist file from the terminal using the following command:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/WebStorm.app
External tools should now also work when WebStorm is not launched from the terminal.
回答6:
I updated node on my local nvm folder from:
/Users/daniel/.nvm/v0.10.33/bin/node
to
/Users/daniel/.nvm/v0.12.2/bin/node
And I get this error:
Failed to list gulp tasks in moda-web/gulpfile.js: external process finished with error exit code 8
/Users/daniel/.nvm/v0.10.33/bin/node
/Users/daniel/.nvm/v0.10.33/lib/node_modules/gulp/bin/gulp.js --no-color --gulpfile /Users/daniel/workspace/www/moda-history/moda-web/gulpfile.js --tasks
Error: `libsass` bindings not found. Try reinstalling `node-sass`?
at getBinding (/Users/daniel/workspace/www/moda-history/moda-web/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:22:11)
at Object.<anonymous> (/Users/daniel/workspace/www/moda-history/moda-web/node_modules/gulp-sass/node_modules/node-sass/lib/index.js:188:23)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/daniel/workspace/www/moda-history/moda-web/node_modules/gulp-sass/index.js:3:17)
at Module._compile (module.js:456:26)
Process finished with exit code 8
I tried everything without any lucky. It was strange that on WebStorm terminal tab I had the correct node version:
$ node -v
v0.12.2
But the "Run Gulp Task" tool it keep using the v0.10.33
My solution: create a new project
thats it.
After I created a new project everything works as expected.
Hope it helps
BR
回答7:
Solved the issue by running open -a webstorm
from the terminal. Not ideal but at least WebStorm gets the same PATH as in the terminal.
来源:https://stackoverflow.com/questions/23927551/webstorm-does-not-recoginize-grunt