grunt: command not found

為{幸葍}努か 提交于 2019-12-10 18:47:01

问题


npm knows that grunt is installed globally, so why isn't it found?

$ npm install -g grunt
... installs ...
$ npm list -g | grep grunt
│   ├─┬ gruntfile-editor@0.2.0
│   ├─┬ gruntfile-editor@0.2.0
├─┬ grunt@0.4.5
│ ├─┬ grunt-legacy-log@0.1.1
│ ├── grunt-legacy-util@0.2.0
$ grunt
-bash: grunt: command not found

I assume because it's put it somewhere that is not on my PATH.

Why doesn't npm just put it somewhere that is on my PATH by default, like /usr/local/bin?

UPDATE: Weirdly, I get the same grunt: command not found error even after I do npm install grunt to run it locally. What am I doing wrong? There is a Gruntfile.js in my repo.


回答1:


The package "grunt" is the task runner itself whereas the "grunt-cli" package is the command line interface that includes the grunt executable. You can make sure that it is installed to the correct path.

If you do npm install grunt-cli it still would not work because this would be installed to node_modules in the corresponding directory which is most likely not on your path. However, when you use grunt from the globally installed CLI tool it will look for an installation of grunt that is local to that project as well as the Gruntfile.js

what you have to do is

  1. install grunt-cli globally:

    $ npm install grunt-cli -g

  2. install grunt local in your dependencies (optionally save the dependency to your package.json):

    $ npm install grunt --save




回答2:


For me there was another thing missing, adding the path to NPM's folder in Window's env variables

  • Go to System (My computer->Properties)
  • Advanced System Settings
  • In Advanced tab, 'Environment Variables'
  • Under User variables, choose Path, then Edit
  • Add this alongside the others you have: '%USERPROFILE%\AppData\Roaming\npm'

Hope this helps, g'luck



来源:https://stackoverflow.com/questions/28479925/grunt-command-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!