Webstorm没有认识Grunt

mak*_*bol 8 macos webstorm gruntjs

所以我搞砸了删除和安装node和npm以安装没有sudo的软件包,现在我无法在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
Run Code Online (Sandbox Code Playgroud)

但奇怪的是,即使在Webstorm中,我也可以从终端运行grunt.截图: 在此输入图像描述

请注意我已grunt-cli安装.

len*_*ena 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.

希望有所帮助.


Cit*_*cid 5

我已经在MacLinux上用适当的~/.bash_profile文件条目解决了这个问题.

说明

WebStorm的开头是:

/bin/bash -l -c "/path/to/webstorm.sh"
Run Code Online (Sandbox Code Playgroud)

-l(短划线L)选项集的bash登录模式.这意味着bash将按顺序读取文件:

  • /etc/profile
  • ~/.bash_profile
  • ~/.bash_login
  • ~/.profile

在-c选项之后运行脚本之前.

我已经付出export PATH~/.bash_profile帮助.

如果您设置PATH~/.bashrc话,就不会因为在登录模式下运行此文件不被读取.

我的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
Run Code Online (Sandbox Code Playgroud)

额外的帮助

这个答案也帮助了我很多.

/sf/answers/1519842411/