25

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?

Shai UI
  • 50,568
  • 73
  • 204
  • 309
  • 2
    Why would you want to disable those warnings? It isn't hard to fix them and they won't be there in production – Craig1123 Feb 09 '18 at 21:24
  • If you insist on ignoring them, the terminal prints a hint on how to do it when you run the start script – Craig1123 Feb 09 '18 at 21:29
  • The hint it for single files, not for all files – Shai UI Feb 09 '18 at 21:29
  • 1
    You can eject and remove eslint from the project – SrThompson Feb 09 '18 at 21:30
  • 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 – Craig1123 Feb 09 '18 at 21:31
  • 2
    @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 – Fen1kz Jul 11 '18 at 14:12

13 Answers13

19

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.

Everettss
  • 15,475
  • 9
  • 72
  • 98
  • 4
    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. – Shai UI Feb 09 '18 at 21:26
  • 1
    I don't think it is currently possible https://github.com/facebook/create-react-app/issues/2157 create-react-app is supposed to be opinionated in opposite to raw react. – Everettss Feb 09 '18 at 21:28
  • I think it's possible if I npm run eject and then configure eslint on my own or something like this – Shai UI Feb 09 '18 at 21:30
  • @foreyez Oh yea you are definitely right about ejecting. It's up to you. – Everettss Feb 09 '18 at 21:31
19

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.

Kevin Hoerr
  • 2,319
  • 1
  • 10
  • 21
  • 4
    adding this file and content doesn't work. note I haven't run eject yet. – Shai UI Feb 09 '18 at 21:36
  • Ah, apparently that's on purpose: https://github.com/facebook/create-react-app/issues/2339 Only solution is to eject. – Kevin Hoerr Feb 09 '18 at 21:38
  • 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. – Kevin Hoerr Feb 09 '18 at 21:45
5

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

/* eslint-disable react/no-direct-mutation-state */
Evhz
  • 8,852
  • 9
  • 51
  • 69
3

Recently the ability to add your own editor configurations was added, this can be used to "partially" disable the functionality of ESLint. You just need to create a configuration file in the root directory.

.eslintrc:

{
  "parser": "babel-eslint"
}

.env

SKIP_PREFLIGHT_CHECK=true

If you create a new application, it will by default come with a pre-filled eslintConfig object in the package.json

3

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.

Mork
  • 55
  • 1
3

To Completely Remove eslint warnings, what you can do is create a file named .eslintignore add * and save it. You wont see any more warning.

*

To Remove warnings from a particular folder means in the .eslintignore file add that folder name

/folder_name
/folder_name/file_name.js

You can also do this in the file level also. Add the following in the beginning of the file

/* eslint-disable */ 

To ignore the next line warning in a file

// eslint-disable-next-line 
yasarui
  • 6,209
  • 8
  • 41
  • 75
3

If you want to disable warnings in DevTools

  1. Open the Console Tab.
  2. Default levels/Custom levels -> uncheck Warnings

enter image description here

Dashiell Rose Bark-Huss
  • 2,173
  • 3
  • 28
  • 48
3

Set the DISABLE_ESLINT_PLUGIN environment variable:

DISABLE_ESLINT_PLUGIN=true npm start
Edward
  • 5,148
  • 2
  • 29
  • 42
2

If you're using create-react-app, then you can go into the package.json and edit the eslintConfig value. I just wanted to disable the "eqeqeq" and "no-unused-vars" rules, so mine looks like this:

"eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ],
    "rules": {
      "eqeqeq": "off",
      "no-unused-vars": "off"
    }
  },

You'll have to re-run npm start for it to take effect.

nda
  • 541
  • 7
  • 18
1

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.

  1. enter this directory

    node_modules/react-dev-utils/webpackHotDevClient.js

  2. look for this function(should be around line 114)

    function handleWarnings(warnings) {

and add a return statement right after it.

Your code should end up looking like this(if you're using webstorm) bye warnings

That should shut the webpackHotDevClient.js:{whateverLineIdontCare} right up. Cheers.

fly
  • 121
  • 1
  • 7
0

Add a .eslintignore file and add

src/*

You can read more about this at

  1. https://eslint.org/docs/user-guide/configuring/ignoring-code
  2. https://eslint.org/docs/user-guide/configuring/rules
0

You can use craco and configure craco.config.js for example

 module.exports = {
  webpack: {
    configure: (webpackConfig) => {
      const ignoreWarnings = [{ module: /some module/, message: /some message/ }]
      return { ...webpackConfig, ignoreWarnings }
    }
  }
}

more details here

0

You can disable the typescript and/or linting errors with setting the environment variables in .env

TSC_COMPILE_ON_ERROR, ESLINT_NO_DEV_ERRORS, to true

more information on advanced configuration for create react app on

https://create-react-app.dev/docs/advanced-configuration/

B.Anas
  • 31
  • 3