通过npm安装ExpressJS时出错

时间:2014-05-28 00:41:06

标签: node.js express

当我尝试运行“npm install -g express”和“npm install -g express-generator”时遇到问题。以下是两者的错误消息。我以前可以使用package.json安装Express,但不能通过npm安装。有任何想法吗? :

“npm install -g express”:

npm http GET https://registry.npmjs.org/express
npm http 304 https://registry.npmjs.org/express
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/express'
npm ERR! error rolling back  express@4.3.1 { [Error: EACCES, unlink '/usr/local/lib/node_modules/express']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/express' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/express'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/express']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/express' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 13.2.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/user/Desktop/Projects/node
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! path /usr/local/lib/node_modules/express
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/express'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/user/Desktop/Projects/node/npm-debug.log
npm ERR! not ok code 0

“npm install -g express-generator”:

npm http GET https://registry.npmjs.org/express-generator
npm http 200 https://registry.npmjs.org/express-generator
npm http GET https://registry.npmjs.org/express-generator/-/express-generator-4.2.0.tgz
npm http 200 https://registry.npmjs.org/express-generator/-/express-generator-4.2.0.tgz
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/express-generator'
npm ERR! error rolling back  express-generator@4.2.0 { [Error: EACCES, unlink '/usr/local/lib/node_modules/express-generator']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/express-generator' }
npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/express-generator'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/express-generator']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/express-generator' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 13.2.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express-generator"
npm ERR! cwd /Users/user/Desktop/Projects/node
npm ERR! node -v v0.10.28
npm ERR! npm -v 1.4.9
npm ERR! path /usr/local/lib/node_modules/express-generator
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, unlink '/usr/local/lib/node_modules/express-generator'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/user/Desktop/Projects/node/npm-debug.log
npm ERR! not ok code 0

4 个答案:

答案 0 :(得分:3)

你试过sudo了吗?看起来当前用户无权访问/usr/local/lib

顺便说一下,您现在要为项目生成器全局安装express-generator,而不是全局express包。

答案 1 :(得分:0)

这是许可问题..

如果您使用不使用sudo,请使用此命令行..

sudo chown -R `whoami` ~/.npm

npm throws error without sudo

此链接是您的最佳答案。

答案 2 :(得分:0)

以管理员身份运行cmd并尝试重新安装。它对我有用。

答案 3 :(得分:0)

我有同样的问题。 我有命令" npm cache clean" - >不行 ulimit -n 2560 - >不工作

所以我 删除.npm目录并运行此命令" npm search -g" 并删除了一些模块 - >在我的情况下grunt *

对我有用。