How to not show warnings in Create React App

36,041

Solution 1

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.

Solution 2

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.

Solution 3

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

/* eslint-disable react/no-direct-mutation-state */

Solution 4

Set the DISABLE_ESLINT_PLUGIN environment variable:

DISABLE_ESLINT_PLUGIN=true npm start

Solution 5

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.

Share:
36,041
Shai UI
Author by

Shai UI

front-end developer in finance. especially html5/javascript/css based apps for mobile/desktop/tablets, node.js on the back-end. my main interests are heavy GUI, 2d/3d, data visualizations. check out my youtube channel: https://www.youtube.com/channel/UCJagBFh6ClHpZ2_EI5a3WlQ

Updated on December 28, 2021

Comments

  • Shai UI
    Shai UI over 2 years

    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?

    • Craig1123
      Craig1123 about 6 years
      Why would you want to disable those warnings? It isn't hard to fix them and they won't be there in production
    • Craig1123
      Craig1123 about 6 years
      If you insist on ignoring them, the terminal prints a hint on how to do it when you run the start script
    • Shai UI
      Shai UI about 6 years
      The hint it for single files, not for all files
    • SrThompson
      SrThompson about 6 years
      You can eject and remove eslint from the project
    • Craig1123
      Craig1123 about 6 years
      You can always remove the entire eslint if you want 0 warnings. If you want a specific rule to stop warning you, edit you .eslintrc file
    • Fen1kz
      Fen1kz almost 6 years
      @Craig1123 I'm not OP, but I want to disable it then when I'm actively prototyping and want to leave all warnings aside until I'm ready to refine the prototype
  • Shai UI
    Shai UI about 6 years
    yes that works, but I don't want to do it for every file. how do I do it for everything. I don't want to see warnings at all.
  • Everettss
    Everettss about 6 years
    I don't think it is currently possible github.com/facebook/create-react-app/issues/2157 create-react-app is supposed to be opinionated in opposite to raw react.
  • Shai UI
    Shai UI about 6 years
    I think it's possible if I npm run eject and then configure eslint on my own or something like this
  • Everettss
    Everettss about 6 years
    @foreyez Oh yea you are definitely right about ejecting. It's up to you.
  • Shai UI
    Shai UI about 6 years
    adding this file and content doesn't work. note I haven't run eject yet.
  • Kevin Hoerr
    Kevin Hoerr about 6 years
    Ah, apparently that's on purpose: github.com/facebook/create-react-app/issues/2339 Only solution is to eject.
  • Kevin Hoerr
    Kevin Hoerr about 6 years
    To clarify, 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.
  • Admin
    Admin about 5 years
    @SilvioBiasiol Yes, as long as you are using CRA 2.x.x+
  • Shamseer Ahammed
    Shamseer Ahammed over 2 years
    This will only hide warning from chrome
  • Dashiell Rose Bark-Huss
    Dashiell Rose Bark-Huss over 2 years
    Yes that's why I specified "in DevTools"