构建时无法在 eslintrc.js 中加载插件 Vue

Mal*_*a T 8 vue.js

Dockerfile 运行RUN npm run build它运行vue-cli-service build. 一段时间后,我收到一个错误.eslintrc.js

无法加载在“.eslintrc.js”中声明的插件“vue”:createRequire 不是函数。由于此问题,构建未完成。

如果我npm run build手动运行,则不会出现此问题。为什么会出现此问题以及如何解决?

.eslintrc.js

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ['plugin:vue/essential', '@vue/airbnb', '@vue/prettier'],
  rules: {
    'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
    'consistent-return': 0,
    'import/extensions': 0,
    'import/no-extraneous-dependencies': 0,
    'no-param-reassign': 0,
    'no-alert': 0,
    'no-unused-expressions': 0,
    'no-shadow': 0,
    'no-return-assign': 0
  },
  plugins: ['prettier'],
  parserOptions: {
    parser: 'babel-eslint'
  }
};

Run Code Online (Sandbox Code Playgroud)

package.json

{
  "name": "web",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint",
    "start": "vue-cli-service serve"
  },
  "dependencies": {
    "axios": "^0.19.2",
    "core-js": "^3.6.5",
    "date-fns": "^2.14.0",
    "humps": "^2.0.1",
    "izitoast": "^1.4.0",
    "lamejs": "^1.2.0",
    "pug-plain-loader": "^1.0.0",
    "register-service-worker": "^1.7.1",
    "sass": "^1.26.5",
    "sass-loader": "^8.0.2",
    "vue": "^2.6.11",
    "vue-resource": "^1.5.1",
    "vue-router": "^3.2.0",
    "vuex": "^3.4.0",
  },
  "devDependencies": {
    "@vue/cli-plugin-babel": "^4.3.1",
    "@vue/cli-plugin-eslint": "^4.3.1",
    "@vue/cli-plugin-pwa": "^4.3.1",
    "@vue/cli-service": "^4.3.1",
    "@vue/eslint-config-airbnb": "^5.0.2",
    "@vue/eslint-config-prettier": "^6.0.0",
    "babel-eslint": "^10.1.0",
    "compression-webpack-plugin": "^4.0.0",
    "eslint": "^7.0.0",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-vue": "^6.2.2",
    "expose-loader": "^0.7.5",
    "material-design-icons-iconfont": "^5.0.1",
    "node-sass": "^4.14.1",
    "vue-cli-plugin-vuetify": "^2.0.5",
    "vue-template-compiler": "^2.6.11",
    "vuetify-loader": "^1.4.3",
    "webpack-bundle-analyzer": "^3.8.0"
  }
}

Run Code Online (Sandbox Code Playgroud)

小智 2

在运行之前你是否运行npm run install安装了所有依赖项npm run build

如果是,也许您需要在.eslintrc文件中添加一些代码:

"parser": "vue-eslint-parser",

最后,您可能还需要添加名为“prettier”的 npm 包才能使其正常工作。