You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to prevent failing to compile on CRA when eslint errors? #10021
Reacted by Jon Seidel, Sergey Ubogov, Adam Bugaj, Artur Baybulatov, Iman Mohamadi, Oliver Timothy, Albert Kostusev, Carla Astrain , Alexander, Miguel Téllez and 86 more
Reacted by Some Name, sangduongit and Juan Menendez
Hmm thanks, this is a kind of workaround, but I don't see it as real solution...
Reacted by Artur Baybulatov, Michal Biros, Kevin Bost, Craig Quincy, Gabriel Ernesto Martínez Cánepa, Trafiz, Esdras Júnior, Thomas DELCROS, Alek Hartzog, Richard Tan and 25 more
The issue with this workaround is that I extend multiple configs... I'd have to override a non-trivial number of rules.
In my case, the ideal would be to apply something like the now-deprecated eslint-loader's emitWarning: true during development. Otherwise without overriding many, many rules, and even with Format on Save applied in my IDE, I am having to spend time fixing eslint errors for code that I am experimenting with and may never actually want to keep.
Only when I run a husky hook or in a pre-build step do I want to run a strict check with an NPM script like: "lint": "eslint --max-warnings 0 --ext .tsx,.ts ./src"
Reacted by Adam Smith, Philipp Brumm, a-tonchev, Thomas Kagan, Rodrigo Roa Rodríguez, Ashfaq Nisar, Gabriel Ernesto Martínez Cánepa, Reza Sam Khaniani, Richard Tan, Jon Seidel and 14 more
This is our exact issue as well. We updated from 3.4.3 and having the build fail for a stray unused import during development is almost hostile. There really should be an option to restore previous behavior.
Reacted by webarnes, David Adams, fitzsimonsdevin, Mikko Koponen, Pete Hanner, Reza Sam Khaniani, Richard Tan, Mel Nunes, Orland, Zeeshan Tamboli and 25 more
This is our exact issue as well. We updated from 3.4.3 and having the build fail for a stray unused import during development is almost hostile. There really should be an option to restore previous behavior.
Couldn't agree more with this. Local development workflow now shot to pieces with this now
Reacted by Gavin Gilmour, David Vogeleer, NicoAdrian, Christen Lofland, David Adams, fitzsimonsdevin, Pete Hanner, Alek Hartzog, Kyle Getrost, Nathan Merritt and 34 more
Burned by this since upgrading today, odd default for a development env.
Reacted by Chase Sawyer, Reza Sam Khaniani, Richard Tan, magiskaoskar, 流浪大法师, Ron Šmeral, Souf G, Max Donchenko, Joonas Häkkinen, Carlo Patti and 4 more
This page has a comment which describes the desired behaviour from CRA < 4:
// We use eslint-loader so even warnings are very visible.
// This is why we prefer to use "WARNING" level for potential errors,
// and we try not to use "ERROR" level at all.
Was there a conscious decision to change this behaviour, or was it just left out of the new linting configuration during the migration away from eslint-loader?
This is a big stopper for me (and most likely for anyone else who extends CRA linting rules beyong it's default). Unless a solution is provied I'll have to revert to a pre 4.0 version. Even doing something as simple as extending eslint's react-app with airbnb will cause a compile error on things that were perviously harmless warnings.
Reacted by Anatoli Semianiaka, Eugene, Corey Light, RINO, David Vogeleer, Santiago Pernigotti, tirmey, Esdras Júnior, Reinis Upītis, Ryan Aquino and 28 more
Team, we are blocked by this as well. Do we have any more insight into what is going on here? What is the rational for failing the build on warnings? It would be good to know the background before we come up with next steps.
We have a large codebase that predates the introduction of eslint and a richer rule set. We keep warnings on to help with on-going clean up without failing builds.
Local development went from smooth to painful. Litteraly have to wait 10 sec for every change made because I added an extra space in my code somewhere and it doesn't compile. Can't debug properly. Rollbacking
Reacted by Pierre Mouchan, Gabriel Ernesto Martínez Cánepa, Y2X, Esdras Júnior, Vilius Roškus, Alicedema, Michael Farník, Reza Sam Khaniani, Richard Tan, citizen-dror and 21 more
Reacted by Ashfaq Nisar, Esdras Júnior, Reza Sam Khaniani, Bluefitdev, PJ and Viktor Shchelochkov
@NicoAdrian If you look at the eslint:recommendedconfig, all rules are errors. You would need to override all of them locally - and all other errors in any other config - and turn them into warnings instead to prevent any error from blocking compilation.
In my case, it's only these two that are showstoppers. It's sub-optimal and I agree with the comments above that refusing to compile in the development environment over an unused variable is pretty hostile. But you'll at least be able to compile and it's simpler than holding back indefinitely.
Reacted by Justin Stahlman, tirmey, 流浪大法师, Jair Avilés, Oleg Derecha and Nikhil
Reacted by Joonas Häkkinen, Artur Gevorgyan, Firmansyah, Carlo Patti, Trung Dang, Emiliano Feitosa, James Kennedy, zilahir, Lauri Telama, Tomasz Zlamaniec and 8 more
@webarnes but this will affect when you really want to lint your project, right? How can we configure a set of rules only for CRA that won't affect linting on CI for example?
You can write eslintrc in Javascript and export a different object in different environments. So you would have different rules in development vs. production. Again, just a stopgap. I think the real solution would be saner defaults in CRA but I also want to keep working.
Sorry for being late but I think this can help others will have the same issue in the future
I only put this line ESLINT_NO_DEV_ERRORS=true in .env and worked as I expected
Reacted by a-tonchev, NixM0nk3y, yuvalsv, Mohamed Azouaoui, Raghav Sharma, Branden Dunbar, Nikita, Hud, Carlos González, Cezary Kuźma and 34 more
Reacted by rahul-sharma-buku and Adnan Bacic
Reacted by Mohamed Azouaoui, Carlos González, Johna, Lucas Barbosa de Sousa, Viktor Shchelochkov , Carlo Patti, Kositsky Alexandr, 404, boro28, Lucas Estima Sussermann and 7 more
And now I can run the app with npm start. However, we can't build it to send it to production. We have a lot on errors and warnings, and we do plan on fixing em. We are fixing our codebase from the ground up, and a lot remains to be cleaned, but the app is functional, and can be shipped. However, it's impossible right now, because of the build.
Looking at the node_modules/react-scripts/config/webpack.config.js file, I understand how the failOnError parameter is configured. It's at false only if it's in development AND we have the variable set. But temporaly, I want this parameter to be at true even while we create our production build. Is that possible? Can we overload part of the webpack.config.js file in our project?
EDIT
Found a workaround. Obviously, it shouldn't be permanent, but this is the only way we have at the moment to make the build work. I DO NOT RECOMMEND IT IF YOU CAN AVOID IT! If you only have a couple errors and warning, now's the time to clean em! If you have a few hundreds... yeah, do that, but clean em reaaaal fast.
In the package.json file, add these variables to your start and build script:
The eslint will be completely disabled on your build. No warnings and errors. Use carefully.
Reacted by Paul Hayes, Vikas Pal, Daniel O., Damir Mukhamedinov, Artem Fokin, Carlos González, Cezary Kuźma, Yehonatan Tsirolnik, Alex Rattray, Arlo Faria and 36 more
Reacted by Vikas Pal, Carlos González, Andrii Trubetskoi, Sebastián Urbano, Carlo Patti, Arman Grigoryan, shoukii, Omar R., Daniel Vasylenko, Theo Okafor and 4 more
Reacted by Vikas Pal, Carlos González, Sebastián Urbano, Carlo Patti, Ankit Tiwari, Daniel Cooke, Marvin Therolf, shoukii, Omar R., Daniel Vasylenko and 6 more
Reacted by Vikas Pal, Carlos González, Carlo Patti, shoukii, Matthias Pichler, Omar R., Theo Okafor, Bryan Hoang, Gabriel Pureliani and Slava Haikin
Thanks, Ive been using Vite for a while and went back to CRA just to build a starter skeleton for projects that Vite can't handle and forgot how annoying that problem was and how it seems it still hasn't got a satisfactory fix yet! Your solution did the trick for now though.... thanks....
@PaulHaze I also switched to Vite, can you share what is possible at CRA, that can not be made with Vite? Just out of curiosity...
Gosh I am probably the wrong person to ask. I'm still very much a beginner when it comes to programming. Especially compared to most people on here. My experience so far with Vite has been great though. Super fast, and feels a less bloated than CRA. Saying that I was working on one project with tailwind in Vite and the refresh was very slow and flickering on every save. For that one I went back to CRA and it worked fine. However since that project the issue hasn't returned and so far its playing nice with every tailwind build I've made with it.....
I create .env file and I am keep getting Compiled with warnings. Line 4:2: Delete · prettier/prettier Line 5:3: Delete·· prettier/prettier Line 6:1: Delete· prettier/prettier
Is it how it should be or I am doing something wrong?
Activity
pascalstr commentedon Nov 5, 2020
Add additional rules to your eslint configuration, it will overwrite error to warn. You have to specify it per rule.
a-tonchev commentedon Nov 5, 2020
Hmm thanks, this is a kind of workaround, but I don't see it as real solution...
chrisahardie commentedon Nov 5, 2020
The issue with this workaround is that I extend multiple configs... I'd have to override a non-trivial number of rules.
In my case, the ideal would be to apply something like the now-deprecated eslint-loader's
emitWarning: trueduring development. Otherwise without overriding many, many rules, and even withFormat on Saveapplied in my IDE, I am having to spend time fixing eslint errors for code that I am experimenting with and may never actually want to keep.Only when I run a husky hook or in a pre-build step do I want to run a strict check with an NPM script like:
"lint": "eslint --max-warnings 0 --ext .tsx,.ts ./src"brumm commentedon Nov 6, 2020
This is our exact issue as well. We updated from 3.4.3 and having the build fail for a stray unused import during development is almost hostile. There really should be an option to restore previous behavior.
cdavid15 commentedon Nov 6, 2020
Couldn't agree more with this. Local development workflow now shot to pieces with this now
gaving commentedon Nov 6, 2020
Burned by this since upgrading today, odd default for a development env.
chrisahardie commentedon Nov 6, 2020
This page has a comment which describes the desired behaviour from CRA < 4:
// We use eslint-loader so even warnings are very visible.
// This is why we prefer to use "WARNING" level for potential errors,
// and we try not to use "ERROR" level at all.
Was there a conscious decision to change this behaviour, or was it just left out of the new linting configuration during the migration away from
eslint-loader?kagant15 commentedon Nov 9, 2020
This is a big stopper for me (and most likely for anyone else who extends CRA linting rules beyong it's default). Unless a solution is provied I'll have to revert to a pre 4.0 version. Even doing something as simple as extending eslint's react-app with airbnb will cause a compile error on things that were perviously harmless warnings.
gone-skiing commentedon Nov 12, 2020
Team, we are blocked by this as well. Do we have any more insight into what is going on here? What is the rational for failing the build on warnings? It would be good to know the background before we come up with next steps.
We have a large codebase that predates the introduction of eslint and a richer rule set. We keep warnings on to help with on-going clean up without failing builds.
NicoAdrian commentedon Nov 16, 2020
Local development went from smooth to painful. Litteraly have to wait 10 sec for every change made because I added an extra space in my code somewhere and it doesn't compile. Can't debug properly. Rollbacking
Lulololu commentedon Nov 17, 2020
Look at this issue : #9887
As they say, commenting out airbnb mentions in the extends array make things work again....
NicoAdrian commentedon Nov 17, 2020
I don't even have airbnb in the extends array in my eslintrc config.
I have only have:
chrisahardie commentedon Nov 17, 2020
@NicoAdrian If you look at the
eslint:recommendedconfig, all rules are errors. You would need to override all of them locally - and all other errors in any other config - and turn them into warnings instead to prevent any error from blocking compilation.NicoAdrian commentedon Nov 17, 2020
@chrisahardie Linting errors didn't block me from compiling before 4.0.0, I don't plan to override settings
4 remaining items
webarnes commentedon Nov 24, 2020
@pascalstr's workaround is a decent option. If you're not using typescript, add something like the following in .eslintrc.json:
{ "rules": { "no-unused-vars": "warn", "react/prop-types": "warn" } }In my case, it's only these two that are showstoppers. It's sub-optimal and I agree with the comments above that refusing to compile in the development environment over an unused variable is pretty hostile. But you'll at least be able to compile and it's simpler than holding back indefinitely.
taschetto commentedon Nov 24, 2020
@webarnes but this will affect when you really want to lint your project, right? How can we configure a set of rules only for CRA that won't affect linting on CI for example?
webarnes commentedon Nov 25, 2020
You can write eslintrc in Javascript and export a different object in different environments. So you would have different rules in development vs. production. Again, just a stopgap. I think the real solution would be saner defaults in CRA but I also want to keep working.
ianschmitz commentedon Nov 25, 2020
Sorry you're running into this. It sounds like a duplicate of #9887. Let's consolidate the information over there if possible. Thanks!
niyodusengaclement commentedon Jun 7, 2021
Sorry for being late but I think this can help others will have the same issue in the future
I only put this line
ESLINT_NO_DEV_ERRORS=truein.envand worked as I expecteda-tonchev commentedon Jun 7, 2021
@niyodusengaclement Thanks, this do the job indeed!
AlexisLessard commentedon Jun 11, 2021
I've done the same in my
package.json, like so:And now I can run the app with
npm start. However, we can't build it to send it to production. We have a lot on errors and warnings, and we do plan on fixing em. We are fixing our codebase from the ground up, and a lot remains to be cleaned, but the app is functional, and can be shipped. However, it's impossible right now, because of the build.Looking at the
node_modules/react-scripts/config/webpack.config.jsfile, I understand how thefailOnErrorparameter is configured. It's atfalseonly if it's in development AND we have the variable set. But temporaly, I want this parameter to be at true even while we create our production build. Is that possible? Can we overload part of thewebpack.config.jsfile in our project?EDIT
Found a workaround. Obviously, it shouldn't be permanent, but this is the only way we have at the moment to make the build work. I DO NOT RECOMMEND IT IF YOU CAN AVOID IT! If you only have a couple errors and warning, now's the time to clean em! If you have a few hundreds... yeah, do that, but clean em reaaaal fast.
In the package.json file, add these variables to your
startandbuildscript:The eslint will be completely disabled on your build. No warnings and errors. Use carefully.
PaulHaze commentedon Jul 8, 2021
Thanks, Ive been using Vite for a while and went back to CRA just to build a starter skeleton for projects that Vite can't handle and forgot how annoying that problem was and how it seems it still hasn't got a satisfactory fix yet! Your solution did the trick for now though.... thanks....
a-tonchev commentedon Jul 9, 2021
@PaulHaze I also switched to Vite, can you share what is possible at CRA, that can not be made with Vite? Just out of curiosity...
PaulHaze commentedon Jul 12, 2021
Gosh I am probably the wrong person to ask. I'm still very much a beginner when it comes to programming. Especially compared to most people on here. My experience so far with Vite has been great though. Super fast, and feels a less bloated than CRA. Saying that I was working on one project with tailwind in Vite and the refresh was very slow and flickering on every save. For that one I went back to CRA and it worked fine. However since that project the issue hasn't returned and so far its playing nice with every tailwind build I've made with it.....
hejuhenryk commentedon Oct 18, 2021
I create .env file and I am keep getting
Compiled with warnings. Line 4:2: Delete·prettier/prettier Line 5:3: Delete··prettier/prettier Line 6:1: Delete·prettier/prettierIs it how it should be or I am doing something wrong?
inioluwa-io commentedon Nov 26, 2021
I fixed mine by adding
ESLINT_NO_DEV_ERRORS=trueandDISABLE_ESLINT_PLUGIN=trueto.env,.env.developmentandenv.productionfilesRohitbels commentedon May 10, 2022
Install
https://github.com/bfanger/eslint-plugin-only-warn
jessewriter commentedon Mar 9, 2023
Failed to load plugin 'only-warn' declared in '.eslintrc.js': Cannot find module 'eslint-plugin-only-warn'