NPM全局安裝依賴權限報錯Error: EACCES: permission denied

最近在安裝electron-forge的時候報錯如下:

➜  ~ sudo npm install -g electron-forge
npm WARN deprecated [email protected]: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated [email protected]: cross-spawn no longer requires a build toolchain, use it instead
npm WARN deprecated [email protected]: wrench.js is deprecated! You should check out fs-extra (https://github.com/jprichardson/node-fs-extra) for any operations you were using wrench for. Thanks for all the usage over the years.
npm WARN deprecated [email protected]: This module relies on Node.js's internals and will break at some point. Do not use it, and update to [email protected].
npm WARN deprecated [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
/usr/local/bin/electron-forge-vscode-win -> /usr/local/lib/node_modules/electron-forge/script/vscode.cmd
/usr/local/bin/forge -> /usr/local/lib/node_modules/electron-forge/dist/electron-forge.js
/usr/local/bin/electron-forge -> /usr/local/lib/node_modules/electron-forge/dist/electron-forge.js
/usr/local/bin/electron-forge-vscode-nix -> /usr/local/lib/node_modules/electron-forge/script/vscode.sh

> [email protected] install /usr/local/lib/node_modules/electron-forge/node_modules/fs-xattr
> node-gyp rebuild

gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/Users/mac/Library/Caches/node-gyp/10.18.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/electron-forge/node_modules/fs-xattr/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron-forge/node_modules/fs-xattr/.node-gyp'
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/electron-forge/node_modules/fs-xattr
gyp ERR! node -v v10.18.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok

> [email protected] install /usr/local/lib/node_modules/electron-forge/node_modules/macos-alias
> node-gyp rebuild

gyp WARN EACCES current user ("nobody") does not have permission to access the dev dir "/Users/mac/Library/Caches/node-gyp/10.18.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/usr/local/lib/node_modules/electron-forge/node_modules/macos-alias/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/electron-forge/node_modules/macos-alias/.node-gyp'
gyp ERR! System Darwin 19.2.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/local/lib/node_modules/electron-forge/node_modules/macos-alias
gyp ERR! node -v v10.18.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok

> [email protected] install /usr/local/lib/node_modules/electron-forge
> node tabtab-install.js

User shell sh not supported, skipping completion install
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/electron-forge/node_modules/fs-xattr):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/electron-forge/node_modules/macos-alias):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ [email protected]
added 4 packages from 2 contributors and updated 1 package in 19.963s

由上述報錯可以看出,很明細是權限問題,但是明明加上了sudo提權啊?爲啥還報錯呢?而且前幾天在Windows中使用CMD管理員權限安裝也會報同樣的錯誤。

那麼可以使用如下參數進行安裝:

sudo npm install -g electron-forge --unsafe-perm

可能是系統檢測到安全性問題了。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章