【问题标题】:Webstorm does not recoginize GruntWebstorm 无法识别 Grunt
【发布时间】:2014-07-18 14:48:38
【问题描述】:

所以我搞砸了删除和安装 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

但奇怪的是我可以从终端运行 grunt,即使在 Webstorm 中也是如此。 截屏:

请注意我安装了grunt-cli

【问题讨论】:

    标签: macos gruntjs webstorm


    【解决方案1】:

    您是否使用 NVM 来管理 Node 版本?该问题可能是由 NVM 用于修补环境变量的方式引起的。通常它会将其初始化逻辑放在 ~/.bashrc

    如果 WebStorm 从终端启动,它会继承终端环境(包括修改 PATH 环境变量,添加 NVM_DIR 环境变量等)。在这种情况下,加载 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,所以 AFAIK 无法编辑启动器。我试图从终端启动 WebStorm,但问题仍然存在。我没有使用 nvm。
    【解决方案2】:

    我已经在 MacLinux 上通过~/.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://stackoverflow.com/a/21712034/1949605

    【讨论】:

      【解决方案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

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题。我通过在/usr/sbin/usr/bin to /usr/local/bin/grunt 中创建符号链接解决了这个问题。

        希望对你有所帮助。

        【讨论】:

          【解决方案5】:

          在这里查看答案后,我用这种方法解决了这个问题: 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>
          

          [Your Path Value] 应该替换为您的系统路径的值(假设您已经可以从终端运行相关命令……即 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 未从终端启动时,外部工具也应该可以工作。

          【讨论】:

            【解决方案6】:

            我从以下位置更新了本地 nvm 文件夹上的节点:

            /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 终端选项卡上我有正确的节点版本:

            $节点-v
            v0.12.2

            但“运行 Gulp 任务”工具一直使用 v0.10.33

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

            就是这样。

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

            希望对你有帮助

            BR

            【讨论】:

              【解决方案7】:

              通过从终端运行open -a webstorm 解决了这个问题。不理想,但至少 WebStorm 获得与终端相同的 PATH。

              【讨论】:

                猜你喜欢
                • 2018-07-13
                • 2019-07-20
                • 2016-12-31
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 1970-01-01
                • 2017-10-18
                相关资源
                最近更新 更多