NPM全局安装依赖权限报错Error: EACCES: permission denied
admin
2023-02-13 15:40:03
0

最近在安装electron-forge的时候报错如下:

➜  ~ sudo npm install -g electron-forge
npm WARN deprecated core-js@2.6.11: 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 cross-spawn-async@2.2.5: cross-spawn no longer requires a build toolchain, use it instead
npm WARN deprecated wrench@1.5.9: 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 natives@1.1.6: This module relies on Node.js's internals and will break at some point. Do not use it, and update to graceful-fs@4.x.
npm WARN deprecated minimatch@0.3.0: 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

> fs-xattr@0.1.17 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

> macos-alias@0.2.11 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

> electron-forge@5.2.4 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: fs-xattr@0.1.17 (node_modules/electron-forge/node_modules/fs-xattr):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs-xattr@0.1.17 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: macos-alias@0.2.11 (node_modules/electron-forge/node_modules/macos-alias):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: macos-alias@0.2.11 install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

+ electron-forge@5.2.4
added 4 packages from 2 contributors and updated 1 package in 19.963s

由上述报错可以看出,很明细是权限问题,但是明明加上了sudo提权啊?为啥还报错呢?而且前几天在Windows中使用CMD管理员权限安装也会报同样的错误。

那么可以使用如下参数进行安装:

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

可能是系统检测到安全性问题了。

相关内容

热门资讯

山西发布山洪蓝色预警,涉8市4... 2026年7月24日下午,山西省水利厅和山西省气象局联合发布山洪灾害气象风险预警,预计未来12小时,...
中央决定:华润集团董事长调整 2026年7月23日,华润(集团)有限公司召开中层以上管理人员大会。中央组织部有关负责同志宣布了党中...
学习笔记丨“努力让每个孩子都能... 制作:王宇峰 岳小乔 贾雪
活力中国调研行丨一束“光”的故... 它被称为“最快的刀”“最准的尺”“最亮的光”。从一束“光”到一颗“芯”,再到规模千亿的产业集群,今天...
携手前沿技术 共创智能未来 携手前沿技术 共创智能未来 ——来自2026年世界互联网大会数字丝路发展论坛的声音 夏日长安,秦岭叠...
上海浩劢取得桌面式轻型悬臂吊专... 国家知识产权局信息显示,上海浩劢工业科技有限公司取得一项名为“桌面式轻型悬臂吊”的专利,授权公告号C...
毒油风暴未歇民进党却急着上架,... 海峡导报综合报道 岛内毒油食安风暴持续延烧,台北市长蒋万安持续号召民众7·25上凯道,但“食药署”2...
WAIC挤满“卖铲人”,但算力... 2026年的WAIC,机器人依然抢占了绝大多数镜头。但展馆里数量增长最快的,是自称“AI Infra...
对话芯展速许玮:“内存墙”下,... Token经济时代,衡量AI价值的标准,正从模型能力转向Token生产效率。AI因此从工具演变为新的...
菲尔兹奖得主邓煜写过这些诗词 邓煜 李少君 徐俪成 | 澎湃新闻记者 徐萧 整理北京时间7月23日晚,中国数学家王虹、邓煜获颁菲尔...