解决报错npm ERR! code EPERMnpm ERR! syscall open


一、报错怎么解决

1、报错代码示例

PS E:\sinosoft\epms\epms-web> npm install
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@achrinza/node-ipc@9.2.2',
npm WARN EBADENGINE   required: { node: '8 || 10 || 12 || 14 || 16 || 17' },
npm WARN EBADENGINE   current: { node: 'v18.17.1', npm: '9.6.7' }
npm WARN EBADENGINE }
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\Program Files (x86)\nodejs\node_cache\_cacache\tmp\5265f024
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'D:\Program Files (x86)\nodejs\node_cache\_cacache\tmp\5265f024'
npm ERR!  [Error: EPERM: operation not permitted, open 'D:\Program Files (x86)\nodejs\node_cache\_cacache\tmp\5265f024'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'D:\\Program Files (x86)\\nodejs\\node_cache\\_cacache\\tmp\\5265f024'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal
PS E:\sinosoft\epms\epms-web> npm run serve

> vue-project@0.1.0 serve
> SET NODE_OPTIONS=--openssl-legacy-provider && vue-cli-service serve

'vue-cli-service' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
PS E:\sinosoft\epms\epms-web> npm install  
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '@achrinza/node-ipc@9.2.2',
npm WARN EBADENGINE   required: { node: '8 || 10 || 12 || 14 || 16 || 17' },
npm WARN EBADENGINE   current: { node: 'v18.17.1', npm: '9.6.7' }
npm WARN EBADENGINE }
npm ERR! code EPERM
npm ERR! syscall open
npm ERR! path D:\Program Files (x86)\nodejs\node_cache\_cacache\tmp\367f5c9c
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, open 'D:\Program Files (x86)\nodejs\node_cache\_cacache\tmp\367f5c9c'
npm ERR!  [Error: EPERM: operation not permitted, open 'D:\Program Files (x86)\nodejs\node_cache\_cacache\tmp\367f5c9c'] {
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'open',
npm ERR!   path: 'D:\\Program Files (x86)\\nodejs\\node_cache\\_cacache\\tmp\\367f5c9c'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.

npm ERR! Log files were not written due to an error writing to the directory: D:\Program Files (x86)\nodejs\node_cache\_logs
npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

2、图片详情

在这里插入图片描述

二、解决方案

注意:看图中报错提示

[Error: EPERM: operation not permitted, open ‘D:\Program Files (x86)\nodejs\node_cache_cacache\tmp\367f5c9c’]

说明这个文件夹权限不足,由此解决方案如下:

1、修改此文件夹权限。使得用户完全控制

在这里插入图片描述

2、全部勾选应用后确认

在这里插入图片描述

### 解决 `npm install` 报错 EPERM 和 EACCES 的方案 当执行 `npm install vue` 或者其他全局安装命令时遇到 `EPERM` 或 `EACCES` 权限错误,通常意味着当前用户缺乏必要的权限去修改某些目录下的文件。这类问题可以通过调整 npm 配置或改变操作方式得到解决。 #### 方法一:更改 npm 缓存位置与全局模块路径 通过重新配置 npm 使用的缓存以及全局模块的位置到用户的 home 目录下可以有效规避权限不足的问题: ```bash mkdir ~/.npm-global npm config set prefix '~/.npm-global' export PATH=~/.npm-global/bin:$PATH echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile source ~/.profile ``` 上述脚本创建了一个新的本地存储区域用于保存全局包,并更新环境变量使得这些工具可以在终端中被调用[^1]。 #### 方法二:使用淘宝镜像加速并尝试再次安装 对于网络连接不稳定的情况,切换至国内更快捷的源可以帮助顺利完成依赖项下载过程: ```bash npm install --registry=https://registry.npm.taobao.org ``` 此命令指定了一个更接近中国大陆地区的服务器作为默认仓库地址,从而提高获取资源的速度和成功率[^2]。 #### 方法三:处理特定于 macOS 的权限问题 在 Mac OS 上即使添加了 sudo 前缀也可能会碰到类似的权限拒绝情况。此时建议按照官方文档指引重设 npm 安全设置或者考虑卸载现有 Node.js 版本再干净地重装最新稳定版[^3]。 #### 方法四:理解根本原因并采取预防措施 实际上很多情况下此类问题是由于试图向受保护系统文件夹内写入数据造成的。为了避免未来发生相同状况,在日常开发过程中应当养成良好习惯——尽可能少地以 root 用户身份运行不必要的程序;同时保持软件版本处于最新状态以便享受安全补丁带来的好处[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值