2015-07-21 165 views
6

我想在nodejs中安裝喲和其他一些軟件包,但是我不斷收到錯誤。我對節點很陌生,所以我有點迷路。 我正在運行Mac OS X 10.10.3。我正在使用的命令是npm安裝不工作,拋出錯誤

sudo npm install --global yo 

這樣做會導致以下錯誤。

> [email protected] postinstall /usr/local/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync 
> node postinstall 

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied 
node.js:720 
    var cwd = process.cwd(); 
        ^
Error: EACCES, permission denied 
    at Error (native) 
    at Function.startup.resolveArgv0 (node.js:720:23) 
    at startup (node.js:63:13) 
    at node.js:814:3 
npm ERR! Darwin 14.3.0 
npm ERR! argv "node" "/usr/local/bin/npm" "install" "--global" "yo" 
npm ERR! node v0.12.7 
npm ERR! npm v2.11.3 
npm ERR! code ELIFECYCLE 

npm ERR! [email protected] postinstall: `node postinstall` 
npm ERR! Exit status 1 
npm ERR! 
npm ERR! Failed at the [email protected] postinstall script 'node postinstall'. 
npm ERR! This is most likely a problem with the spawn-sync package, 
npm ERR! not with npm itself. 
npm ERR! Tell the author that this fails on your system: 
npm ERR!  node postinstall 
npm ERR! You can get their info via: 
npm ERR!  npm owner ls spawn-sync 
npm ERR! There is likely additional logging output above. 

npm ERR! Please include the following file with any support request: 
npm ERR!  /Users/XXXXXXX/npm-debug.log 
+0

您是如何安裝節點的? – a0viedo

回答

15

通常,您不應該使用sudo來安裝節點模塊。 而是使用sudo來修復文件夾權限,以允許您執行全局npm安裝。在.npm目錄的

採取所有權與

sudo chown -R $(whoami) ~/.npm 

而寫的node_modules目錄權限與

sudo chown -R $USER /usr/local/lib/node_modules 

然後嘗試運行您的NPM install命令再次沒有須藤。

+0

我仍然有相同的錯誤。有什麼建議麼?我偶然發現這篇文章http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo。我重新安裝節點也...沒有運氣。 –

+0

你最初是否使用sudo安裝過任何東西? – snozza

+0

我不這麼認爲。無論如何要完全刪除節點並重新安裝它? –

5

從你的Reddit帖子,我知道 sudo npm cache clean修復了你的問題。 有人應該在這裏回答,以便任何其他人想要解決這個問題可以找到它。

1

運行以下命令應解決該問題。

sudo npm cache clean 
sudo npm install -g yo