Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not show warnings in Create React App

I'm using create-react-app from Facebook, when it starts via 'npm start' it shows me a list of warnings, such as:

'Bla' is defined but never used
Expected '===' and instead saw '=='

I don't want to see any of these warnings, is there a way to supress them?

like image 358
Shai UI Avatar asked Feb 09 '18 21:02

Shai UI


People also ask

Should I eject my create React app?

If you ask me, I recommend you to either write and maintain your own configuration or you use other React app builder like Next. js, which has custom webpack config built-in. If you use CRA, then accept the limitations and don't eject from it.

Can you code React offline?

To make our app work offline, we need to get the web assets to work offline. Create React App already has the required boilerplate for making an app offline using service workers. Open src/index.


4 Answers

Those warnings come from eslint. To disable them add /* eslint-disable */ at the top of the file you don't want to follow the eslint rules.

like image 51
Everettss Avatar answered Oct 12 '22 19:10

Everettss


For local Eslint, add a file to your project named .eslintignore and add any directories or files you want to ignore:

build/
src/
*.js

Though you might as well remove it entirely at this point.


This doesn't work with building or starting the code however, if you are using create-react-app. There is no way to disable Eslint without ejecting because it's built into react-scripts. Anytime any you build or start the server, it will run eslint using its internal configs aside from special cases defined in package.json. The only way around that is to eject or prepend each file with the disable comment as mentioned elsewhere. See this issue on Github for more information.

like image 31
Kevin Hoerr Avatar answered Oct 12 '22 19:10

Kevin Hoerr


For specific eslint warning supression insert the following code at the beginning of the file.

/* eslint-disable react/no-direct-mutation-state */
like image 28
Evhz Avatar answered Oct 12 '22 19:10

Evhz


My rep is not high enough to comment on @fly's excellent answer, so I'll C+P it to add this instead:

For anyone looking for a temporary but quick and effective workaround for disabling console warnings from DevTools, this might do the trick.

Disclaimer - this might not work on versions that are not mine(react-scripts v3.0.1, react-dev-utils@^9.0.1), so use it at your own risk.

  • enter this directory

node_modules/react-dev-utils/webpackHotDevClient.js

  • look for this function(should be around line 114)

function handleWarnings(warnings) {

  • either add the return at the start of function printWarnings() (line 124), or comment out the call to printWarnings() in line 145.

  • restart, eg with npm run start, for change to take effect.

This way, the hot reloader continues to work, but the annoying warnings which have already been caught in my editor are not output in the browser.

like image 42
Mork Avatar answered Oct 12 '22 19:10

Mork