【问题标题】:npm install not working, throwing errorsnpm install 不工作,抛出错误
【发布时间】:2015-10-11 05:56:20
【问题描述】:

我正在尝试在 nodejs 中安装 yo 和其他一些软件包,但是我不断收到错误消息。我是节点新手,所以我有点迷茫。 我正在运行 Mac OS X 10.10.3。我使用的命令是

sudo npm install --global yo

这样做会给我以下错误。

> spawn-sync@1.0.13 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! spawn-sync@1.0.13 postinstall: `node postinstall`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the spawn-sync@1.0.13 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

【问题讨论】:

  • 你是如何安装节点的?

标签: node.js macos npm


【解决方案1】:

运行以下命令应该可以解决问题。

sudo npm cache clean
sudo npm install -g yo 

【讨论】:

    【解决方案2】:

    从您的 Reddit 帖子中,我知道 sudo npm cache clean 为您解决了这个问题。 认为应该有人在这里回答,以便其他想要解决这个问题的人可以找到它。

    【讨论】:

      【解决方案3】:

      一般来说,您不应该使用 sudo 来安装节点模块。 相反,请使用 sudo 修复您的文件夹权限,以允许您进行全局 npm 安装。

      使用

      获得 .npm 目录的所有权
      sudo chown -R $(whoami) ~/.npm
      

      以及对node_modules目录的写权限

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

      然后尝试再次运行您的 npm install 命令不使用 sudo。

      【讨论】:

      • 我仍然有同样的错误。有什么建议?我偶然发现了这篇文章stackoverflow.com/questions/16151018/…。我也重新安装了节点......没有运气。
      • 你最初用 sudo 安装过什么吗?
      • 我不这么认为。无论如何要完全删除节点并重新安装它吗?
      • 试试npm install --global --unsafe-perm yo
      • 不用担心。非常肯定这是一个权限问题。作为最后的努力,请尝试以下操作:github.com/sindresorhus/guides/blob/master/… 这些人遇到了与您类似的问题,上述指南已解决:github.com/yeoman/yo/issues/253 希望能解决问题。告诉我们进展如何
      猜你喜欢
      • 2021-12-18
      • 2018-10-30
      • 1970-01-01
      • 2018-01-17
      • 1970-01-01
      • 2018-03-24
      • 2021-07-28
      相关资源
      最近更新 更多