安装 gatsby-cil 失败:npm ERR! sh:1:node-gyp-build:权限被拒绝

问题描述 投票:0回答:1

我尝试使用 npm 在 WLS2 上安装 gatsby-cil,但失败了。

这是错误消息

root@LAPTOP-7EEFPLOM:~# npm install -g gatsby-cli
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v16.14.0/lib/node_modules/gatsby-cli/node_modules/lmdb
npm ERR! command failed
npm ERR! command sh -c node-gyp-build
npm ERR! sh: 1: node-gyp-build: Permission denied

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2022-03-14T01_49_08_533Z-debug-0.log

我一开始以为是 WSL 的问题,然后我尝试在云服务器上做同样的事情,得到了同样的结果。

我也尝试了网上找到的解决方案:

npm config set user 0
npm config set unsafe-perm true

但仍然遇到同样的错误

shell npm unix gatsby
1个回答
2
投票

尝试:

sudo chown -R $(whoami) ~/

您似乎没有足够的权限(在两种环境中)来安装全局包,因此更改

~/
权限文件夹可能会解决您的问题。

由于这不是与 Gatsby 相关的问题(来自其依赖项),您还可以尝试使用

sudo
权限单独安装它们。在这种情况下:

sudo npm install -g node-gyp node-pre-gyp node-gyp-build

然后你应该能够再次安装

gatsby-cli
,这应该跳过
node-gyp
包装。

© www.soinside.com 2019 - 2024. All rights reserved.