VUE3 自学第三课 ESLint 版本不兼容导致代码运行报错解决方法

PS D:\demo\my-vue-project\src> npm install eslint-plugin-vue@latest --save-dev
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: my-vue-project@0.1.0
npm error Found: eslint@7.32.0
npm error node_modules/eslint
npm error dev eslint@“^7.32.0” from the root project
npm error
npm error Could not resolve dependency:
npm error peer eslint@“^8.57.0 || ^9.0.0” from eslint-plugin-vue@10.4.0
npm error node_modules/eslint-plugin-vue
npm error dev eslint-plugin-vue@“10.4.0” 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.
npm error
npm error
npm error For a full report see:
npm error C:\Users\Admin\AppData\Local\npm-cache_logs\2025-08-08T07_20_31_139Z-eresolve-report.txt
npm error A complete log of this run can be found in: C:\Users\Admin\AppData\Local\npm-cache_logs\2025-08-08T07_20_31_139Z-debug-0.log
PS D:\demo\my-vue-project\src>
这个错误是因为 eslint-plugin-vue@latest(最新版本)要求 ESLint 版本为 ^8.57.0 或 ^9.0.0,但你的项目当前使用的是 ESLint 7.32.0,版本不兼容导致的依赖冲突。

**解决方案:**安装兼容版本的 eslint-plugin-vue
不需要升级 ESLint,直接安装与 ESLint 7.x 兼容的 eslint-plugin-vue 版本即可:
bash
npm install eslint-plugin-vue@9.21.0 --save-dev
这个版本的 eslint-plugin-vue 支持 ESLint 7.x,能解决依赖冲突,同时也支持 Vue 3 的

此时 ESLint 会正确识别 defineProps 等 Vue 3 语法,报错应该会消失。
如果仍有问题,可直接用 --legacy-peer-deps 忽略依赖冲突(不推荐,但应急有效):
bash
npm install eslint-plugin-vue@latest --save-dev --legacy-peer-deps

在这里插入图片描述

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值