node.js - Grunt 安装错误 : "should be installed with -g"

标签 node.js npm gruntjs

我正在尝试在我的计算机上安装 Grunt。我读过一些tutorials并关注installation docs ,但我无法让它工作。

CLI 使用以下命令安装正常:

sudo npm install -g grunt-cli

当我选择本地目录(包含 package.json 和 Gruntfile)和 npm install 时,我看到以下消息:

npm WARN prefer global <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="543326213a207937383d14647a657a6d" rel="noreferrer noopener nofollow">[email protected]</a> should be installed with -g

为什么会发生这种情况?我确实使用 -g 安装 - 意思是“全局”,我明白。

此后,我似乎无法运行 grunt,例如:

$ grunt
-bash: grunt: command not found
$ grunt --version
-bash: grunt: command not found

我该如何解决这个问题?我错过了什么?

这是我的完整日志:

$ sudo npm install -g grunt-cli
Password:
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/nopt
npm http GET https://registry.npmjs.org/findup-sync
npm http GET https://registry.npmjs.org/resolve
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/abbrev
npm http GET https://registry.npmjs.org/glob
npm http GET https://registry.npmjs.org/lodash
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/minimatch
npm http GET https://registry.npmjs.org/graceful-fs
npm http GET https://registry.npmjs.org/inherits
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
npm http GET https://registry.npmjs.org/lru-cache
npm http GET https://registry.npmjs.org/sigmund
/Users/tonyMac/.node/bin/grunt -> /Users/tonyMac/.node/lib/node_modules/grunt-cli/bin/grunt
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e28590978c96cf818e8ba2d2ccd3ccd3d2" rel="noreferrer noopener nofollow">[email protected]</a> /Users/tonyMac/.node/lib/node_modules/grunt-cli
├── <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="740611071b18021134445a475a45" rel="noreferrer noopener nofollow">[email protected]</a>
├── <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a6c8c9d6d2e6978896889796" rel="noreferrer noopener nofollow">[email protected]</a> (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0160636373647741302f312f35" rel="noreferrer noopener nofollow">[email protected]</a>)
└── <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ddbbb4b3b9a8adf0aea4b3be9dedf3ecf3ef" rel="noreferrer noopener nofollow">[email protected]</a> (<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f39f9c9792809bb3c2ddc3ddc2" rel="noreferrer noopener nofollow">[email protected]</a>, <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f2959e9d90b2c1dcc3dcc0c3" rel="noreferrer noopener nofollow">[email protected]</a>)
Tonys-iMac:~ tonyMac$ cd projects/testingGrunt
Tonys-iMac:testingGrunt tonyMac$ npm install
npm WARN prefer global <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3e594c4b504a135d52577e0e100f1007" rel="noreferrer noopener nofollow">[email protected]</a> should be installed with -g

最佳答案

您不应使用 sudo 来安装软件包。
如果您使用sudo,则在安装node和npm时会出现问题。
我看到您使用 OSX,所以请相信我,使用 brew 数据包管理器 ( http://brew.sh ) 安装 Node ,并让它为您处理 Node 和 npm。

先删除 Node ,然后按照说明安装 Brew。 然后,您只需输入 brew install node ,一切就会变得非常顺利。

关于node.js - Grunt 安装错误 : "should be installed with -g",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19778249/

相关文章:

javascript - 如何从浏览器中读取 .AppImage

npm - `npm version patch`命令失败

node.js - 安装 verdaccio 后发布到 NPM

javascript - 如何使用 grunt autoprefixer 定位 IE9 及更高版本?

node.js - 使用 nodejs、grunt 或 gulp 合并文件夹的最佳方法

javascript - 设置环境变量 grunt 或 grunt-exec

node.js - node.js 邮件监听器多久轮询一次邮箱?

node.js - 从请求url中获取IP地址

javascript - 断言错误: Target cannot be null or undefined

javascript - 为什么前端框架在 NPM 中?