项目中的package.json无法安装npm

17

在我的Macbook Air上,我只能使用sudo全局安装npm包,但是每次进入本地目录并尝试安装本地包时,如果不加-g选项,就会出现错误。

 npm ERR! Error: EACCES, open '/Users/mmarze/.npm/53951495-coffee-script.lock'
npm ERR!  { [Error: EACCES, open '/Users/mmarze/.npm/53951495-coffee-script.lock']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/Users/mmarze/.npm/53951495-coffee-script.lock' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! System Darwin 12.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "coffee-script"
npm ERR! cwd /Users/mmarze/sandbox/node.js/test
npm ERR! node -v v0.8.9
npm ERR! npm -v 1.1.61
npm ERR! path /Users/mmarze/.npm/53951495-coffee-script.lock
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/Users/mmarze/.npm/53951495-coffee-script.lock'
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/mmarze/sandbox/node.js/test/npm-debug.log
npm ERR! not ok code 0

我尝试卸载并重新安装node和npm,但无法在本地安装任何东西。如果我使用sudo在本地安装,则我的本地用户没有对它们的写访问权限。我该如何解决这个问题?


1
“/Users/mmarze/.npm”的所有者是谁?/Users/mmarze/sandbox/node.js/test/npm-debug.log中有什么有趣的东西吗? - Bruno Grieder
2
看起来你可能已经做了一个 sudo npm install ... 没有使用 -g,即以 root 用户的身份在你的个人主目录下安装了 npm 包。要么清除你的 .npm 目录,要么运行 chown -R mmarze.mmarze ~/.npm 来解决问题。 - Linus Thiel
谢谢,看起来已经解决了问题! - Mmarzex
1个回答

28

根据Linus G Thiel的评论,看起来这个修复了问题:

看起来你可能已经做了一个没有使用-gsudo npm install ...,即将npm包安装在root用户的home目录下。要么清除你的.npm目录,要么执行chown -R mmarze.mmarze ~/.npm应该可以解决它。


当你使用sudo安装npm的第一个东西时,似乎也会出现这种情况。 - Akrikos
请注意,在OSX上,您需要在用户和组之间使用“:”(冒号)而不是点。 - 0skar
请注意,您可能还需要为已安装在项目中的模块修复权限:chown -R mmarze:mmarze ./node_modules - Julian D.
username.username 是什么意思?(在上面的例子中是 mmarze.mmarze - Connor Leech
你可能需要在chown命令前加上sudo。 - Leo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接