eslint version conflict with TypeScript — how to fix
Quick Answer
# ESLint 9 (flat config) — use latest @typescript-eslint
npm install --save-dev eslint@^9 @typescript-eslint/parser@^8 @typescript-eslint/eslint-plugin@^8
# ESLint 8 (legacy config) — use v6
npm install --save-dev eslint@^8 @typescript-eslint/parser@^6 @typescript-eslint/eslint-plugin@^6
When this happens
npm ERR! peer eslint@"^8.56.0" from @typescript-eslint/[email protected]
npm ERR! node_modules/@typescript-eslint/eslint-plugin
npm ERR! Conflicting peer dependency: [email protected]
ESLint and @typescript-eslint must be at compatible major versions.
Other causes & fixes
Check current installed versions
npm ls eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
ESLint 9 flat config — eslint.config.js
// eslint.config.js (ESLint 9)
import tseslint from 'typescript-eslint';
export default tseslint.config(
...tseslint.configs.recommended
);
ESLint 8 legacy config — .eslintrc.json
// .eslintrc.json (ESLint 8)
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"]
}
Find which package is requesting the conflicting version
The package named in the peer dependency error is not always the package you installed directly. Inspect the dependency tree before pinning a version.
npm ls eslint @typescript-eslint/parser @typescript-eslint/eslint-plugin
npm explain eslint
node --version
npm --version
Align the config format with the ESLint major version
ESLint 9 projects normally use eslint.config.js, while older projects may still use .eslintrc. Do not upgrade only ESLint while leaving the parser and plugin on an incompatible major version.
# Check peer requirements before installing
npm view @typescript-eslint/parser peerDependencies
npm view @typescript-eslint/eslint-plugin peerDependencies
# Reinstall a matching set after choosing ESLint 8 or 9
npm install --save-dev eslint@<major> @typescript-eslint/parser@<major> @typescript-eslint/eslint-plugin@<major>
Related