48

I've recently created a project with create-react-project.

The problem is that, while I'm developing, every time there's a problem with ESLint, the build breaks and doesn't compile the code.

Can I keep the build running while still having ESLint running and reporting errors that I will fix later?

Danziger
  • 19,628
  • 4
  • 53
  • 83
R01010010
  • 5,670
  • 11
  • 47
  • 77

6 Answers6

59

If you want to force ESLint to always emit warnings (that will not stop you build) instead of errors, you need to set emitWarning: true:

{
    enforce: 'pre',
    include: paths.appSrc,
    test: /\.(js|jsx|mjs)$/,
    use: [{
        loader: require.resolve('eslint-loader'),
        options: {
            formatter: eslintFormatter,
            eslintPath: require.resolve('eslint'),
            emitWarning: true,  HERE
        },
    }],
},

As stated in the docs:

Errors and Warning

By default the loader will auto adjust error reporting depending on eslint errors/warnings counts. You can still force this behavior by using emitError or emitWarning options:

  • emitError (default: false)

    Loader will always return errors if this option is set to true.

  • emitWarning (default: false)

    Loader will always return warnings if option is set to true. If you're using hot module replacement, you may wish to enable this in development, or else updates will be skipped when there's an eslint error.

  • ...

Danziger
  • 19,628
  • 4
  • 53
  • 83
21

just add DISABLE_ESLINT_PLUGIN=true in your .envfile

cheers !

janadari ekanayaka
  • 3,742
  • 2
  • 13
  • 17
5

since eslint-loader is now deprecated and eslint-webpack-plugin is now used in create-react-app check the docs, I was able to solve a similar issue by adding two option to the eslint-webpack-plugin

after ejecting your react app, add these options to the ESLintPlugin options:

      new ESLintPlugin({
        // Plugin options
        extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'],
        formatter: require.resolve('react-dev-utils/eslintFormatter'),
        eslintPath: require.resolve('eslint'),
        context: paths.appSrc,
        failOnError: false,  <== `This one`
        emitWarning: true,  <== `And this one`
        // ESLint class options
        cwd: paths.appPath,
        resolvePluginsRelativeTo: __dirname,
        baseConfig: {
          extends: [require.resolve('eslint-config-react-app/base')],
          rules: {
            ...(!hasJsxRuntime && {
              'react/react-in-jsx-scope': 'error'
            })
          }
        }
      })
Ali Aljarah
  • 1,326
  • 2
  • 9
  • 16
  • 6
    What if I don't want to eject? – loxosceles Jan 22 '21 at 12:18
  • I tried some solutions but it didn't solve the problem. one of them is to hide the warning inside the code and instead the app will only show it in the terminal, but that didn't suite me since I want the errors and warnings to appear in the code. – Ali Aljarah Jan 26 '21 at 16:53
3

I might be late for the answer but if you add ESLINT_NO_DEV_ERRORS=true in the .env file then the error is sorted.

P.S: it works with react script 4.0.3 and above

Vikas Bansal
  • 10,662
  • 14
  • 58
  • 100
2

For people wanting to solve this problem in 2021, you can simply set following in your .env.development file to ignore TypeScript Errors

TSC_COMPILE_ON_ERROR=true

Source: https://create-react-app.dev/docs/advanced-configuration/#:~:text=TSC_COMPILE_ON_ERROR

Also, to ignore ESLint errors, use craco to override eslint-webpack-plugin default configuration to ignore errors in development environment.

const eslintWebpackPlugin = require("eslint-webpack-plugin");
const process = require("process");
module.exports = {
  webpack: {
    configure: (config) => {
      config.plugins.forEach((plugin) => {
        if (plugin instanceof eslintWebpackPlugin) {
          // Ignore ESLint Errors.
          plugin.options.failOnError = process.env.NODE_ENV === "production";
        }
      });
      return config;
    },
  },
};
Hariom Balhara
  • 832
  • 8
  • 19
  • This is really a bad solution because why we use TypeScript is to throw errors at compile stage! – Tamer Durgun Aug 09 '22 at 08:37
  • Which is why the solution suggests to do it when you are not in production mode – Hariom Balhara Aug 10 '22 at 12:37
  • You should have compile errors at the dev stage to prevent wrong code moves on to the production stage. Don't you commit changes after development? – Tamer Durgun Aug 12 '22 at 04:28
  • 1
    When you are developing things, you may want instant feedback and not stuck on solving TS errors(when you already know that the code isn't ready to be commited or pushed or ready for review). Frankly this is a preference of the developer – Hariom Balhara Aug 12 '22 at 05:00
-1

Ok I just commented this lines from my webpack config

  // {
  //   test: /\.(js|jsx|mjs)$/,
  //   enforce: 'pre',
  //   use: [
  //     {
  //       options: {
  //         formatter: eslintFormatter,
  //         eslintPath: require.resolve('eslint'),
  //
  //       },
  //       loader: require.resolve('eslint-loader'),
  //     },
  //   ],
  //   include: paths.appSrc,
  // },
R01010010
  • 5,670
  • 11
  • 47
  • 77