简体   繁体   English

允许 create-react-app 编译带有 ESLint 错误

[英]Allow create-react-app to compile with ESLint errors

I recently added ESLint and prettier with a bunch of configurations to create-react-app.我最近在 create-react-app 中添加了 ESLint 和 prettier 以及一系列配置。

Here are the packages:这里是包:

"eslint-config-airbnb": "^18.2.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-jsx-a11y": "^6.4.1",
"eslint-plugin-prettier": "^3.1.4",
"prettier": "^2.1.2",

Now, the problem is that the development server fails to compile, because there are loads of ESLint errors in the project.现在,问题是开发服务器无法编译,因为项目中存在大量 ESLint 错误。 It says:它说:

Failed to compile

*list of errors*

This error occurred during the build time and cannot be dismissed.

This is highly intrusive.这是非常具有侵入性的。 I need it to still be able to compile as I don't see a reason for it to refuse to do so because or some styling issues.我需要它仍然能够编译,因为我看不出它有理由拒绝这样做,因为或某些样式问题。

How can I prevent this from happening without doing some hack like setting all ESLint errors to warning level.如何在不进行一些黑客攻击的情况下防止这种情况发生,例如将所有 ESLint 错误设置为警告级别。 I also do not want to eject.我也不想弹出。

I also wish not to put everything into .eslintigore during development as this would be very annoying for my team to have to change that file over and over during development.我也不希望在开发过程.eslintigore所有内容都放入.eslintigore中,因为这会让我的团队在开发过程中一遍又一遍地更改该文件非常烦人。

Any help is appreciated.任何帮助表示赞赏。

I was having exactly the same problem after using a Vite for a while and then returning to CRA and installing my usual Airbnb linting tools.在使用 Vite 一段时间然后返回 CRA 并安装我常用的 Airbnb linting 工具后,我遇到了完全相同的问题。 I found THIS solution on Github which basically says to add these lines to your package.json starting scripts我在 Github 上找到了这个解决方案,它基本上是说将这些行添加到你的 package.json 启动脚本中

"start": "ESLINT_NO_DEV_ERRORS='true'  react-scripts start",  
"build": "DISABLE_ESLINT_PLUGIN='true' react-scripts build",

This did the trick for me.这对我有用。 It kept the linting errors showing in the code but unless they were breaking the code it compiled and ran no problem.它保留了代码中显示的 linting 错误,但除非他们破坏了它编译的代码并且运行没有问题。

I don't think this is a long term solution, but it will do for a workaround...我不认为这是一个长期的解决方案,但它可以作为一种解决方法......

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

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