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.
src/common/api.ts
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
Notice that 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, it is possible to disable this behavior.
I thought defining a custom version in package.json
will solve the issue, 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
.
Want to leave a comment?
Join the discussion at Twitter or Mastodon. Feel free to drop me an email. 💌