Webstorm无法识别Grunt。

8

我曾尝试在没有使用sudo的情况下安装包,结果搞乱了node和npm的安装和卸载。现在我无法在Webstorm中使用Grunt面板。

错误信息如下:

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

但是奇怪的是我可以从终端运行grunt,甚至在Webstorm中也可以。

截图: enter image description here

请注意我已经安装了grunt-cli

7个回答

8
您是否使用NVM来管理Node版本?问题可能是由NVM使用的修补环境变量的方式引起的。通常,它将其初始化逻辑放在〜/ .bashrc中。
如果WebStorm是从终端启动的,则继承终端环境(包括修改的PATH环境变量,添加的NVM_DIR env var等)。在这种情况下,加载Grunt任务没有问题,因为WebStorm看到正确的PATH值。
如果WebStorm是从桌面启动的(而不是从终端启动),则WebStorm会看到错误的PATH值,并且无法加载Grunt任务。
如果您正在使用bash作为shell,则解决方法可能如下:编辑WebStorm启动器,并将命令设置为“/ bin / bash -l -c” / path / to / webstorm.sh“。此命令将执行bash登录(即读取您的.bashrc / .bash_profile文件),然后运行webstorm.sh。
希望这能有所帮助。

我使用的是Mac OS X Mavericks,据我所知,无法编辑启动器。我尝试从终端启动WebStorm,问题仍然存在。我没有使用nvm。 - makbol

5

我已经在Mac和Linux上通过在~/.bash_profile文件中添加正确的条目来解决了这个问题。

解释

WebStorm是通过以下方式启动的:

/bin/bash -l -c "/path/to/webstorm.sh"
-l (连字符L)选项将bash设置为登录模式。这意味着bash将按顺序读取文件:
  • /etc/profile
  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile
在-c选项后运行脚本之前。
我已经将export PATH放置到~/.bash_profile中,这有所帮助。
如果您在~/.bashrc中设置了PATH,则它将不起作用,因为在登录模式下不会读取此文件。
我的Mac的~/.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

其他帮助

这个答案对我也有很大的帮助。

https://dev59.com/42Ik5IYBdhLWcg3wWs9z#21712034


3

我遇到了同样的问题,我的解决方法是:

首先全局安装grunt cli工具:

npm install -g grunt-cli (或者可能需要使用sudo npm install -g grunt-cli)。

你可以通过输入grunt --version命令来确定是否成功安装。

现在,你可以在你的项目中本地安装当前版本的Grunt。所以从你的项目位置开始...

npm install grunt --save-dev

你可以在以下链接中找到更多信息:

Node package ( Grunt ) installed but not available


0

我在本地的nvm文件夹中更新了node:

/Users/daniel/.nvm/v0.10.33/bin/node

/Users/daniel/.nvm/v0.12.2/bin/node

我遇到了这个错误:

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

我尝试了所有的方法都没有成功。奇怪的是,在WebStorm终端选项卡中,我有正确的node版本:

$ node -v
v0.12.2

但是,“运行Gulp任务”工具仍然使用v0.10.33

我的解决方案:创建一个新项目

就这样。

创建一个新项目后,一切都按预期工作。

希望能帮到你。

敬礼


0

在查看这里的答案后,我使用以下方法解决了这个问题: http://ify.io/getting-webstorm-external-tools-to-work-on-webstorm-on-osx/

首先,如果WebStorm当前已打开,请关闭它。然后将以下条目添加到“/Applications/Webstorm.app/Contents/Info.plist”文件中。

<key>LSEnvironment</key>
<dict>
    <key>PATH</key>
    <string>[Your Path Value]</string>
</dict>

[您的路径值] 应该替换为您系统路径的值(假设您已经可以从终端运行相关命令...例如 npm、grunt 等)。请注意,可以使用以下终端命令检索系统路径:

echo $PATH

此命令只是从 ~/.MacOSX/environment.plist 中检索 PATH 值。

我没有执行这一步骤,但它仍然可以工作。如果您遇到问题,请尝试执行此步骤

现在,请使用以下命令从终端刷新更新后的 Info.plist 文件:

/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/WebStorm.app

现在,即使没有从终端启动WebStorm,外部工具也应该可以正常工作。


0

我曾经遇到过同样的问题。我通过在 /usr/sbin/usr/bin 中创建符号链接指向 /usr/local/bin/grunt 来解决它。

希望这能帮到你。


0
通过在终端中运行open -a webstorm解决了这个问题。虽然不是理想的解决方法,但至少WebStorm能够获得与终端相同的路径。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接