Darek Kay's picture Darek Kay

Using a custom ESLint version in Create React App

I'm maintaining my own ESLint rules for all my projects. With Create React App (CRA), custom configuration is always a hassle (by design). Custom rules are usually fine, unless the ESLint peer dependency version doesn't support them yet:

$ react-scripts build
Creating an optimized production build...
Failed to compile.

Definition for rule 'react/jsx-no-constructed-context-values' was not found react/jsx-no-constructed-context-values
Definition for rule 'no-unsafe-optional-chaining' was not found no-unsafe-optional-chaining

I thought defining a recent version of ESlint in package.json will solve the issue of rules not being found, but react-scripts doesn't pick it up:

"devDependencies": {
"eslint": "7.17.0",

Finally, with yarn resolutions, I was able to override (peer) dependency versions:

"resolutions": {
"eslint": "7.17.0",
"eslint-plugin-react": "7.22.0"

Note: this method relies on using yarn instead of npm.

Bonus tip: As of CRA version 4.0.0, react-scripts build (and react-scripts start) run eslint implicitly, which sounds like a strange decision. As of version 4.0.2, you can disable this behavior by adding DISABLE_ESLINT_PLUGIN to your .env file.

Related posts

Want to leave a comment?

Join the discussion at Twitter or Mastodon. Feel free to drop me an email. 💌

Using a custom ESLint version in Create React App