项目环境:jeecgboot-vue3@3.8.1、npm v8+/v9+、Node16+
报错关键字:npm error ERESOLVE unable to resolve dependency tree
一、完整报错信息
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: jeecgboot-vue3@3.8.1
npm error Found: stylelint@16.26.1
npm error node_modules/stylelint
npm error dev stylelint@"^16.12.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer stylelint@">= 11.x < 15" from stylelint-config-prettier@9.0.5
npm error node_modules/stylelint-config-prettier
npm error dev stylelint-config-prettier@"^9.0.5" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
二、报错根因详解
npm7+开启了严格peer依赖校验,本次为stylelint生态版本不兼容导致冲突:
- 项目当前安装:
stylelint@16.26.1(16大版本) - 依赖约束:
stylelint-config-prettier@9.0.5强制要求 stylelint 版本 大于等于11、小于15 - 版本区间无交集,npm直接阻断依赖安装,抛出ERESOLVE依赖树解析错误
补充:JeecgBoot-Vue3 3.8.1 内置lint配置老旧,默认搭配低版本prettier规则插件,无法适配新版stylelint16
三、三套解决方案(按推荐优先级排序)
✅ 方案一:升级lint插件(根治推荐,无后遗症)
升级stylelint-config-prettier至10.x版本,原生兼容stylelint16,适配项目原有代码规范,无需修改lint配置文件。
- 修改项目
package.json开发依赖
"devDependencies": {
"stylelint": "^16.12.0",
"stylelint-config-prettier": "^10.0.0",
"stylelint-config-standard": "^36.0.0"
}
- 清空旧依赖缓存,干净重装
# Windows 终端执行
rd /s /q node_modules
del package-lock.json
npm i
# Mac / Linux 终端执行
rm -rf node_modules package-lock.json
npm install
✅ 方案二:降级stylelint(不想改插件,兼容老规范)
锁定stylelint为14.x稳定版,满足 <15 版本约束,适配原有9.x版本prettier规则插件。
- 修改
package.json版本
"devDependencies": {
"stylelint": "^14.16.1",
"stylelint-config-prettier": "^9.0.5"
}
- 删除依赖锁文件,重装依赖即可
✅ 方案三:临时绕过校验(快速安装,应急使用)
不修改依赖版本,绕过npm严格peer依赖校验,适合临时启动项目、打包调试,长期开发不推荐,大概率会出现stylelint校验报错。
1、稳妥绕过(优先使用)
复用npm6宽松依赖解析规则,兼容性更强
npm install --legacy-peer-deps
2、强制覆盖(风险较高)
强行合并依赖,极易导致lint命令失效、项目运行报错
npm install --force
3、全局永久开启宽松模式
后续所有项目npm安装自动绕过peer依赖冲突
npm config set legacy-peer-deps true
四、方案优劣对比
| 解决方案 | 优点 | 缺点 | 适用场景 |
|---|---|---|---|
| 升级lint插件 | 根治冲突、规范最新、无运行bug | 极小概率微调stylelint配置 | 长期开发、团队协同 |
| 降级stylelint | 零配置修改、适配老项目规范 | 依赖版本老旧,缺少新校验能力 | 老项目维稳、不想改动代码规范 |
| –legacy-peer-deps | 一键执行、无需改代码 | 依赖兼容不稳定,lint易报错 | 本地临时跑项目、打包应急 |
五、避坑小贴士
- JeecgBoot-Vue3 3.8.x 版本,优先选用【方案一】统一升级整套stylelint生态,适配度最高;
- 使用
--legacy-peer-deps安装后,若执行npm run lint:style报错,必须升级/降级依赖版本,无法绕过; - 每次切换依赖版本,务必删除
node_modules+package-lock.json,避免缓存残留导致二次报错。
正文完
可以使用微信扫码关注公众号(ID:xzluomor)