Linux,  Vue

解决eslint-plugin-vue构建报错

一项目背景

在构建前端Vue工程时,遇到下述错误:

+ npm config set registry http://nexus.celoan.opt/repository/npm-public/
+ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: goods@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.
npm ERR! 
npm ERR! See /root/.npm/eresolve-report.txt for a full report.
​
npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2024-07-11T09_36_42_223Z-debug-0.log
Build step 'Execute shell' marked build as failure
Finished: FAILURE

二 解决错误

从报错日志,看应该是eslint-plugin-vue依赖的版本不对。参考GitHub上有网友提出的issue,以及解决办法,把该依赖的版本改为7.20.0。

将package.json中的”eslint-plugin-vue”: “^8.0.3″,修改为”eslint-plugin-vue”: “^7.20.0″。下述是修改后的文件。

{
 "name": "gxd-backend-multi-ui",
 "version": "0.1.0",
 "private": true,
 "scripts": {
   "serve": "vue-cli-service serve",
   "build": "vue-cli-service build",
   "lint": "eslint --ext .js,.vue src",
   "build:prod": "vue-cli-service build",
   "build:stage": "vue-cli-service build --mode staging",
   "dev": "vue-cli-service serve",
   "preview": "node build/index.js --preview"
},
 "dependencies": {
   "@riophae/vue-treeselect": "0.4.0",
   "axios": "0.24.0",
   "clipboard": "2.0.8",
   "core-js": "3.25.3",
   "echarts": "5.4.0",
   "element-ui": "2.15.12",
   "file-saver": "2.0.5",
   "fuse.js": "6.4.3",
   "gxdpt-components": "^1.0.18",
   "highlight.js": "9.18.5",
   "js-beautify": "1.13.0",
   "js-cookie": "3.0.1",
   "jsencrypt": "3.0.0-rc.1",
   "nprogress": "0.2.0",
   "quill": "1.3.7",
   "screenfull": "5.0.2",
   "sortablejs": "1.10.2",
   "vue": "^2.6.14",
   "vue-count-to": "1.0.13",
   "vue-cropper": "0.5.5",
   "vue-meta": "2.4.0",
   "vue-pdf": "^4.1.0",
   "vue-router": "3.4.9",
   "vuedraggable": "2.24.3",
   "vuex": "3.6.0",
   "watermark-dom": "^2.3.0"
},
 "devDependencies": {
   "@babel/core": "^7.12.16",
   "@babel/eslint-parser": "^7.12.16",
   "@vue/cli-plugin-babel": "4.4.6",
   "@vue/cli-plugin-eslint": "4.4.6",
   "@vue/cli-service": "4.4.6",
   "@vue/eslint-config-standard": "^6.1.0",
   "babel-eslint": "10.1.0",
   "babel-plugin-dynamic-import-node": "2.3.3",
   "chalk": "4.1.0",
   "compression-webpack-plugin": "5.0.2",
   "connect": "3.6.6",
   "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": "^7.20.0",
   "lint-staged": "^11.1.2",
   "runjs": "4.4.2",
   "sass": "1.32.13",
   "sass-loader": "10.1.1",
   "script-ext-html-webpack-plugin": "2.1.5",
   "svg-sprite-loader": "5.1.1",
   "vue-template-compiler": "2.6.12"
},
 "engines": {
   "node": ">=8.9",
   "npm": ">= 3.0.0"
},
 "gitHooks": {
   "pre-commit": "lint-staged"
},
 "husky": {
   "hooks": {
     "pre-commit": "lint-staged"
  }
},
 "keywords": [
   "vue",
   "admin",
   "dashboard",
   "element-ui",
   "boilerplate",
   "admin-template",
   "management-system"
],
 "repository": {
   "type": "git",
   "url": "https://gitee.com/y_project/RuoYi-Cloud.git"
}
}

三 重新构建

+ npm config set registry http://nexus.celoan.opt/repository/npm-public/
+ npm install
npm WARN ERESOLVE overriding peer dependency
npm WARN deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.

....
added 1700 packages in 49s

161 packages are looking for funding
run `npm fund` for details
+ npm run build:prod

> goods@0.1.0 build:prod
> vue-cli-service build

四 参考链接

https://github.com/vuejs/eslint-config-standard/issues/24

留言