Vue3项目部署Netlify时遇ESLint依赖冲突,求解决方案
Vue3项目ESLint依赖冲突解决办法
错误信息
npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: portfolio@0.1.0 npm ERR! Found: eslint-plugin-vue@8.7.1 npm ERR! node_modules/eslint-plugin-vue npm ERR! dev eslint-plugin-vue@"^8.0.3" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer eslint-plugin-vue@"^7.0.0" from @vue/eslint-config-standard@6.1.0 npm ERR! node_modules/@vue/eslint-config-standard npm ERR! dev @vue/eslint-config-standard@"^6.1.0" from the root project npm ERR! npm ERR! Fix the upstream dependency conflict, or retry npm ERR! this command with --force or --legacy-peer-deps npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
项目package.json配置
{ "name": "portfolio", "version": "0.1.0", "private": true, "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", "lint": "vue-cli-service lint" }, "dependencies": { "core-js": "^3.8.3", "vue": "^3.2.13", "vue-router": "^4.0.3" }, "devDependencies": { "@babel/core": "^7.12.16", "@babel/eslint-parser": "^7.12.16", "@vue/cli-plugin-babel": "~5.0.0", "@vue/cli-plugin-eslint": "~5.0.0", "@vue/cli-plugin-router": "~5.0.0", "@vue/cli-service": "~5.0.0", "@vue/eslint-config-standard": "^6.1.0", "eslint": "^7.32.0", "eslint-plugin-import": "^2.25.3", "eslint-plugin-node": "^11.1.0", "eslint-plugin-promise": "^5.1.0", "eslint-plugin-vue": "^8.0.3" }, "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ "plugin:vue/vue3-essential", "@vue/standard" ], "parserOptions": { "parser": "@babel/eslint-parser" }, "rules": {} }, "browserslist": [ "> 1%", "last 2 versions", "not dead", "not ie 11" ] }
可行解决办法
方案1:升级ESLint标准配置包(推荐)
@vue/eslint-config-standard@6.x仅支持eslint-plugin-vue@7.x,而你的项目安装了eslint-plugin-vue@8.x。升级配置包到7.x版本即可兼容:
- 修改
package.json中devDependencies里的"@vue/eslint-config-standard": "^6.1.0"为"@vue/eslint-config-standard": "^7.0.0" - 删除
node_modules和package-lock.json文件 - 执行
npm install
方案2:降级ESLint Vue插件
如果不想升级配置包,可以将eslint-plugin-vue降级到7.x版本,匹配配置包的peer依赖要求:
- 修改
package.json中devDependencies里的"eslint-plugin-vue": "^8.0.3"为"eslint-plugin-vue": "^7.20.0" - 删除
node_modules和package-lock.json文件 - 执行
npm install
方案3:跳过peer依赖检查(临时应急)
使用npm的--legacy-peer-deps参数绕过依赖冲突检查,适合快速恢复开发,但可能存在潜在兼容性问题,不推荐长期使用:
npm install --legacy-peer-deps
内容的提问来源于stack exchange,提问作者Jack Gee
相关产品推荐
相关产品推荐

