执行npm install失败:ESLint依赖冲突问题求助
ESLint依赖树冲突问题排查方案
问题描述
在Ubuntu系统执行npm install时触发ESLint相关依赖树解析错误,环境版本:npm 9.6.3、node 18.15.0。核心冲突为项目依赖的eslint@7.32.0与eslint-plugin-vue@6.2.2要求的peer依赖eslint@^5.0.0 || ^6.0.0不兼容,更换npm/node版本后问题仍存在。
报错信息
npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree npm ERR! npm ERR! While resolving: taxihub-admin@1.0.0 npm ERR! Found: eslint@7.32.0 npm ERR! node_modules/eslint npm ERR! dev eslint@"^7.32.0" from the root project npm ERR! npm ERR! Could not resolve dependency: npm ERR! peer eslint@"^5.0.0 || ^6.0.0" from eslint-plugin-vue@6.2.2 npm ERR! node_modules/eslint-plugin-vue npm ERR! dev eslint-plugin-vue@"^6.2.2" 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关键配置
"dependencies": { "@johmun/vue-tags-input": "^2.1.0", "apexcharts": "^3.19.3", "babel-polyfill": "^6.26.0", "bootstrap": "^4.5.0", "bootstrap-vue": "^2.15.0", "chart.js": "^2.9.3", "core-js": "^3.6.5", "echarts": "^4.8.0", "es6-promise": "^4.2.8", "firebase": "^7.16.1", "font-awesome": "^4.7.0", "mobile-device-detect": "^0.4.3", "nprogress": "^0.2.0", "v-calendar": "^1.0.8", "v2-datepicker": "^3.1.1", "vue": "^2.6.11", "vue-apexcharts": "^1.6.0", "vue-chartjs": "^3.5.0", "vue-clickaway": "^2.2.2", "vue-cropperjs": "^4.1.0", "vue-echarts": "^5.0.0-beta.0", "vue-flag-icon": "^1.0.6", "vue-fontawesome-icon": "^1.3.0", "vue-form-wizard": "^0.8.4", "vue-good-table": "^2.19.5", "vue-i18n": "^8.18.2", "vue-instantsearch": "^2.7.0", "vue-jstree": "^2.1.6", "vue-lazyload": "^1.3.3", "vue-meta": "^2.4.0", "vue-perfect-scrollbar": "^0.2.1", "vue-router": "^3.3.4", "vue-simple-calendar": "^4.4.0", "vue-slider-component": "^3.2.2", "vue-star-rating": "^1.6.1", "vue-sweetalert2": "^3.0.6", "vue-the-mask": "^0.11.1", "vue-tour": "^1.5.0", "vue2-daterange-picker": "^0.5.1", "vue2-editor": "^2.10.2", "vuedraggable": "^2.24.0", "vuejs-smart-table": "0.0.5", "vuelidate": "^0.7.5", "vuetable-2": "^1.7.5", "vuex": "^3.5.1" }, "devDependencies": { "@vue/cli-plugin-babel": "^4.4.6", "@vue/cli-plugin-eslint": "^6.8.0", "@vue/cli-service": "^4.4.6", "@vue/eslint-config-prettier": "^6.0.0", "babel-eslint": "^10.1.0", "copy-webpack-plugin": "^6.0.3", "eslint": "^7.32.0", "eslint-plugin-vue": "^6.2.2", "node-sass": "^4.14.1", "sass-loader": "^9.0.2", "vue-loader": "^15.9.3", "vue-template-compiler": "^2.6.11" }, "eslintConfig": { "root": true, "env": { "node": true }, "extends": [ "plugin:vue/essential", "eslint:recommended" ], "rules": {}, "parserOptions": { "parser": "babel-eslint" } }
解决方案
方案一:对齐依赖版本(推荐)
选择以下任一方式调整依赖,确保ESLint版本满足插件要求:
- 降级ESLint到6.x版本:修改package.json中
devDependencies里的eslint为^6.8.0,执行以下命令重装:rm -rf node_modules package-lock.json npm install - 升级eslint-plugin-vue到兼容版本:
eslint-plugin-vue@7.x开始支持ESLint 7,修改package.json中devDependencies里的eslint-plugin-vue为^7.0.0,同样删除node_modules和锁文件后执行npm install。
方案二:使用npm兼容参数
如果暂时不想调整版本,可通过参数忽略peer依赖冲突:
- 执行
npm install --legacy-peer-deps:该参数会跳过peer依赖的严格校验,适配旧项目依赖场景,风险较低 - 执行
npm install --force:强制安装依赖,但可能引发未知兼容性问题,仅临时应急使用
方案三:修复Vue CLI插件版本不匹配问题
当前@vue/cli-plugin-eslint@6.8.0与@vue/cli-service@4.4.6版本不一致,Vue CLI插件版本需与核心服务版本对齐,修改@vue/cli-plugin-eslint为^4.4.6,再执行重装命令。
内容的提问来源于stack exchange,提问作者Ariel
相关产品推荐
相关产品推荐

