【问题标题】:Failed to Load Plugin Vue in eslintrc.js When Building构建时无法在 eslintrc.js 中加载插件 Vue
【发布时间】:2021-11-06 02:13:22
【问题描述】:

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'
  }
};

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"
  }
}

【问题讨论】:

  • 我通过从 Node10 升级到 Node12 解决了这个问题

标签: vue.js


【解决方案1】:

在运行npm run build之前,你有没有运行npm run install来安装所有依赖项?

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

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

最后,您可能还需要添加名为 'prettier' 的 npm 包以使其工作。

【讨论】:

    猜你喜欢
    • 2022-07-05
    • 1970-01-01
    • 2022-11-03
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    相关资源
    最近更新 更多