简体   繁体   English

Eslint 会因 Vue 项目中的任何错误而中断构建

[英]Eslint breaks build for any error in a Vue project

At some point in one of my Vue projects Eslint started breaking builds due to any error (such as "Strings must use singlequote", or "Variable declared but never used").在我的一个 Vue 项目中的某个时刻,Eslint 由于任何错误(例如“字符串必须使用单引号”或“变量声明但从未使用”)开始破坏构建。 Also the formatting errors are not corrected automatically (although they should?).此外,格式错误不会自动更正(尽管它们应该?)。 I don't know when exatly this happened and what caused it.我不知道这到底是什么时候发生的,是什么原因造成的。 Could be after some npm install .可能是在一些npm install

I have found multiple suggestions to solve the problem by adding emitWarning: true to eslint config, but it does not work form me unfortunatelly.我找到了多个解决问题的建议,方法是在 eslint 配置中添加emitWarning: true ,但不幸的是它对我不起作用。

It seems to me that sometimes the first attempt to build is successfull and errors are "detected" and thrown only after I change something in the code, save and the server restars.在我看来,有时第一次构建尝试是成功的,并且只有在我更改代码中的某些内容、保存并重新启动服务器后才会“检测到”错误并抛出错误。 Also eslint seems to care only about files that are actually open in VS Code at the moment, if I close a file and restart, eslint no longer cares that the formatting is incorrect there.此外,eslint 似乎只关心目前在 VS Code 中实际打开的文件,如果我关闭文件并重新启动,eslint 不再关心那里的格式不正确。

Here's my .eslintrc.js contents:这是我的.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
    }
};

My other Vue project works fine.我的另一个 Vue 项目运行良好。 I'm not able to pinpoint any meaningful differences in setup.我无法确定设置中的任何有意义的差异。

How to stop eslint from breaking builds?如何阻止 eslint 破坏构建? What else can be wrong here?这里还有什么问题? I'll be greatful for any help!我会很乐意提供任何帮助!

You can make the build command skip ESlint by changing the build script in the package.json file:您可以通过更改package.json文件中的build脚本来使构建命令跳过 ESlint:

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

Replace the plugin with the appropriate one if that's not the one being used in your project.如果该插件不是您项目中使用的插件,请将其替换为合适的插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM