微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

node.js – 如何在不出错的情况下安装grunt-cli?

在Chris Coyier的 post的启发下,我决定放弃咕噜咕噜.但是我在设置方面遇到了很大的问题.

首先,我安装了Node.

然后我将package.json文件添加到我的项目根目录,包括

{
  "name": "example-project","version": "0.1.0","devDependencies": {
    "grunt": "~0.4.1"
  }
}

然后我运行了npm install

最后,我运行了npm install -g grunt-cli

它带来了大量的错误

npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm ERR! Error: EACCES,mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR!  { [Error: EACCES,mkdir '/usr/local/lib/node_modules/grunt-cli']
npm ERR!   errno: 3,npm ERR!   code: 'EACCES',npm ERR!   path: '/usr/local/lib/node_modules/grunt-cli',npm ERR!   fstream_type: 'Directory',npm ERR!   fstream_path: '/usr/local/lib/node_modules/grunt-cli',npm ERR!   fstream_class: 'DirWriter',npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /Users/bryce/repo
npm ERR! node -v v0.10.23
npm ERR! npm -v 1.3.17
npm ERR! path /usr/local/lib/node_modules/grunt-cli
npm ERR! fstream_path /usr/local/lib/node_modules/grunt-cli
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES,mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/bryce/repo/npm-debug.log
npm ERR! not ok code 0
Bryce:repo bryce$npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm ERR! Error: EACCES,mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/bryce/repo/npm-debug.log
npm ERR! not ok code 0

我假设上述错误是我尝试运行grunt的原因,我只是得到-bash:grunt:command not found

那里的任何人都知道发生了什么事吗?

解决方法

所有这一切都是添加’sudo’,因为我没有认安装grunt-cli的权限.运行以下命令并输入密码后,它按预期工作.

sudo npm install -g grunt-cli

希望这有助于某人!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐