【问题标题】:Eslint breaks build for any error in a Vue projectEslint 会因 Vue 项目中的任何错误而中断构建
【发布时间】:2021-01-02 16:53:02
【问题描述】:

在我的一个 Vue 项目中,Eslint 因任何错误(例如“字符串必须使用单引号”或“声明但从未使用的变量”)而开始破坏构建。格式错误也不会自动更正(尽管它们应该?)。我不知道这是什么时候发生的以及是什么原因造成的。可能在npm install之后。

我找到了多个通过将emitWarning: true 添加到 eslint 配置来解决问题的建议,但不幸的是,它对我不起作用。

在我看来,有时第一次构建尝试是成功的,并且只有在我更改代码中的某些内容、保存并重新启动服务器之后才会“检测到”错误并抛出错误。此外,eslint 似乎只关心目前在 VS Code 中实际打开的文件,如果我关闭文件并重新启动,eslint 不再关心那里的格式不正确。

这是我的.eslintrc.js 内容:

module.exports = {
    root: true,
    env: {
        node: true,
        "es6": true
    },
    extends: [
        "plugin:vue/essential",
        "@vue/standard"
    ],
    rules: {
        "no-console": process.env.NODE_ENV === "production" ? "error" : "off",
        "no-debugger": process.env.NODE_ENV === "production" ? "error" : "off",
        "indent": ["error", 4],
        "semi": ["error", "always"],
        "space-before-function-paren": ["error", "never"],
        "quotes": ["error", "single"]
    },
    parserOptions: {
        parser: "babel-eslint",
        sourceType: "module",
        ecmaVersion: 6,
        emitWarning: true, // tried with and without this
        emitError: false, // tried with and without this
        failOnError: false, // tried with and without this
        failOnWarning: false // tried with and without this
    }
};

我的另一个 Vue 项目运行良好。我无法确定设置中的任何有意义的差异。

如何阻止 eslint 破坏构建?这里还有什么问题?如有任何帮助,我将不胜感激!

【问题讨论】:

    标签: vue.js eslint eslintrc


    【解决方案1】:

    您可以通过更改 package.json 文件中的 build 脚本来使构建命令跳过 ESlint:

    "scripts": {
        "build": "vue-cli-service build --skip-plugins @vue/cli-plugin-eslint",
    }
    

    如果您的项目中没有使用相应的插件,请将其替换为适当的插件。

    【讨论】:

    • 非常感谢!我看到某些格式仍在更正中 - 如果该插件被禁用,该怎么办?在 VS Code 中,我也禁用了 formatOnSave,所以它不是 VS 代码。
    • @Eggon 或许您应该在vue.config.js 文件中将lintOnSave 设置为false
    猜你喜欢
    • 2018-12-09
    • 2018-04-15
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 2020-04-25
    • 2022-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多