Windows安装npm淘宝镜像npm ERR! errno -4048 npm ERR! code EPERM npm ERR! syscall unlink

本文详细讲述了遇到npm EPERM错误时的解决方案,包括检查文件权限、以管理员身份运行命令、更换npm源、升级Node.js版本等步骤。适合开发者解决开发过程中的常见问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



  • 【版权所有,文章允许转载,但须以链接方式注明源地址,否则追究法律责任】
  • 【创作不易,点个赞就是对我最大的支持】


前言

仅作为学习笔记,供大家参考
总结的不错的话,记得点赞收藏关注哦!



一、报错信息


permissions of the file and its containing directories, or try running npm ERR!



npm ERR! code EPERM
npm ERR! syscall unlink
npm ERR! path D:\BanGong\eclipse\WorkSpeace\JooLun-wx\joolun-wx-ui\node_modules\.staging\ant-design-vue-a7f0335c\dist\antd-with-locales.min.js
npm ERR! errno -4048
npm ERR! Error: EPERM: operation not permitted, unlink 'D:\BanGong\eclipse\WorkSpeace\JooLun-wx\joolun-wx-ui\node_modules\.staging\ant-design-vue-a7f0335c\dist\antd-with-locales.min.js'
npm ERR!  [OperationalError: EPERM: operation not permitted, unlink 'D:\BanGong\eclipse\WorkSpeace\JooLun-wx\joolun-wx-ui\node_modules\.staging\ant-design-vue-a7f0335c\dist\antd-with-lo
cales.min.js'] {
npm ERR!   cause: [Error: EPERM: operation not permitted, unlink 'D:\BanGong\eclipse\WorkSpeace\JooLun-wx\joolun-wx-ui\node_modules\.staging\ant-design-vue-a7f0335c\dist\antd-with-local
es.min.js'] {
npm ERR!     errno: -4048,
npm ERR!     code: 'EPERM',
npm ERR!     syscall: 'unlink',
npm ERR!     path: 'D:\\BanGong\\eclipse\\WorkSpeace\\JooLun-wx\\joolun-wx-ui\\node_modules\\.staging\\ant-design-vue-a7f0335c\\dist\\antd-with-locales.min.js'
npm ERR!   },
npm ERR!   errno: -4048,
npm ERR!   code: 'EPERM',
npm ERR!   syscall: 'unlink',
npm ERR!   path: 'D:\\BanGong\\eclipse\\WorkSpeace\\JooLun-wx\\joolun-wx-ui\\node_modules\\.staging\\ant-design-vue-a7f0335c\\dist\\antd-with-locales.min.js',
npm ERR!   parent: '@smallwei/avue'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
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! A complete log of this run can be found in:
npm ERR!     D:\BanGong\npm\node_cache\_logs\2022-06-01T01_48_26_519Z-debug.log

二、解决方法



  1. 点击Windows按键,搜索命令提示符,如图:(一定要点击以管理员身份运行)
    在这里插入图片描述

  2. 我项目在d盘输入 d: 然后一步一步找到项目路径的前台项目下(如图)

  3. 在这里插入图片描述

  4. 输入:npm install -g cnpm --registry=https://registry.npm.taobao.org --verbose

  5. 等待下载,结果如图:
    在这里插入图片描述

注:如还是不能npm run dev按我的方法走一遍,删除node_modules文件重新走一遍

1.npm install --registry=https://registry.npm.taobao.org

2. 如提示‘vue-cli-service‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。执行:
npm install -g @vue/cli-service

3,安装vue,输入命令

npm install vue

4,安装vue-cli,输入命令

npm install --global vue-cli

5.(如报这个错A complete log if this run can be found in)执行全局更新
npm install npm -g
或者用淘宝镜像命令
cnpm install npm -g

在这里插入图片描述

查看node与npm版本是否匹配

指定npm版本命令:npm install -g npm@6.14.5

如果报这个错,node版本过低,下载个nvm,之后安装nvm install 14.1.0

npm ERR! vote@1.0.0 dev: `vite`

问题记录
报这个错,npm install --forace
在这里插入图片描述

三、状态码为:9 报错信息

node: --openssl-legacy-provider is not allowed in NODE_OPTIONS
npm ERR! code ELIFECYCLE
npm ERR! errno 9
npm ERR! ruoyi@3.8.6 dev: `set NODE_OPTIONS=--openssl-legacy-provider & vue-cli-service serve`
npm ERR! Exit status 9
npm ERR!
npm ERR! Failed at the ruoyi@3.8.6 dev script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\BanGong\npm\node_cache\_logs\2023-12-08T01_42_13_159Z-debug.log

解决方法

  1. node版本过低,使用最新版本完美解决

  2. 我上一版本使用的是14,升级到了最新的20

  3. 下载最新版本:
    nvm install 20.10.0

  4. 通过nvm切换版本:
    nvm use 20.10.0

  5. nvm list查看是否切换成功

如果帮助到你,三连顶一下,创作不易~


公众号:程序员温眉

在这里插入图片描述
优快云:程序员温眉

每天进步一点点的程序员

### 解决方案 `EPERM: operation not permitted` 错误通常表示 Node.js 或 npm 尝试执行某些操作时被操作系统拒绝权限[^1]。以下是针对该问题的具体解决方案: #### 1. 清理缓存 有时,npm 缓存可能会导致冲突或错误。可以通过清理缓存来解决问题: ```bash npm cache clean --force ``` #### 2. 更改文件夹权限 如果项目所在的目录存在权限问题,可以尝试更改其访问权限。例如,在 Windows 上右键点击项目文件夹并设置完全控制权限给当前用户。 #### 3. 使用管理员模式运行命令提示符 在 Windows 平台上,以管理员身份运行命令提示符可能有助于解决权限不足的问题[^2]: - 右击“命令提示符”图标 -> “以管理员身份运行”。 #### 4. 配置全局安装路径 默认情况下,npm 的全局模块存储位置可能是受保护的系统区域。通过重新配置全局路径到用户可写的位置,能够有效规避此问题: ```bash mkdir ~/.npm-global npm config set prefix '~/.npm-global' export PATH=~/.npm-global/bin:$PATH source ~/.profile ``` 上述脚本适用于 Linux 和 macOS;对于 Windows 用户,则需手动调整 `NODE_PATH` 环境变量指向新的全局路径。 #### 5. 升级Node.js版本 旧版Node.js可能存在兼容性缺陷从而引发此类异常行为。建议升级至最新稳定发行版[^4]: ```bash nvm install --lts nvm use --lts ``` #### 示例代码片段展示如何验证修复效果 下面提供了一段简单的测试程序用于确认以上措施是否奏效: ```javascript const fs = require('fs'); try { fs.writeFileSync('./test.txt', 'Hello, world!', { flag: 'w' }); console.log("File write successful."); } catch (err) { console.error(`Failed to write file: ${err.message}`); } ```
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值