开发避坑短篇(3):解决@vitejs plugin-vue@5.0.5对Vite^5.0.0的依赖冲突

异常信息
# npm resolution error report


While resolving:system@3.8.8
Found: vite@6.2.3
node_modules/vite
  dev vite@"6.2.3" from the root project


Could not resolve dependency:
peer vite@"^5.0.0" from @vitejs/plugin-vue@5.0.5
node_modules/@vitejs/plugin-vue
  dev @vitejs/plugin-vue@"5.0.5" from the root project


Fix the upstream dependency conflict, or retry
this command with --force or --legacy-peer-deps
to accept an incorrect (and potentially broken) dependency resolution.
异常背景

刚从gitlab克隆下来的源码,首次执行npm install安装依赖时报错,当前node.js的版本为20.18.0

* 20.18.0 (Currently using 64-bit executable)
  16.15.1
  10.14.1
异常分析

翻译错误信息:

在解析system@3.8.8 时发现:
当前安装的 vite 版本为 6.2.3
位于 node_modules/vite 目录
项目根目录中指定开发依赖 vite@“6.2.3”

无法解析的依赖项:
@vitejs/plugin-vue@5.0.5 要求 peer 依赖 vite@“^5.0.0”
位于 node_modules/@vitejs/plugin-vue 目录
项目根目录中指定开发依赖 @vitejs/plugin-vue@“5.0.5”

解决方法:
修复上游依赖冲突,或使用 --force 或 --legacy-peer-deps 参数重试命令
这将接受一个不正确(且可能损坏)的依赖解析方案

查看package.json文件中指定的@vitejs/plugin-vue的版本

{
  "name": "system",
  "version": "3.8.8",
  "description": "xxx系统",
  ...
  "scripts": {
    "dev": "vite",
    "build:prod": "vite build",
    "build:stage": "vite build --mode staging",
    "preview": "vite preview"
  },
  ...
  "dependencies": {
    "@element-plus/icons-vue": "2.3.1",
    ...
  },
  "devDependencies": {
    "@vitejs/plugin-vue": "5.0.5",
	...
  }
}
解决方法

实际上刚克隆下来的源码还没有任何依赖,也就是 /node_modules目录都还没有,所以根据提示,强制下载依赖包,执行以下命令:

npm install --force or --legacy-peer-deps

–force 参数:强制覆盖本地缓存和版本限制,重新下载远程资源‌。

–legacy-peer-deps 参数:忽略对等依赖(如 Vue 插件与 Vite 版本不匹配)‌)的版本检查,采用 npm v4-v6 的宽松解析逻辑‌。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

帧栈

您的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值