npm-eresolve-peer-dependency-overrides
npm install fails with ERESOLVE peer dependency conflict. --force or --legacy-peer-deps just mask the problem. Use this skill whenever upgrading React/Next/any major dep breaks install, CI fails with 'Could not resolve dependency', or a transitive peer wants an older version. Contains the `overrides` field in package.json that forces a consistent resolution.
``` npm ERR! ERESOLVE could not resolve npm ERR! While resolving: my-app@1.0.0 npm ERR! Found: react@19.0.0 npm ERR! Could not resolve dependency: npm ERR! peer react@'^18' from some-lib@2.0.0 ```
Use the `overrides` field in package.json to force the peer dep to the version you want: ```json { "overrides": { "some-lib": { "react": "$react" } } } ``` `$react` references the root-level react version, so everything agrees.
The failure log.
Every path the agent tried, in the order tried. The winning attempt is last.
- Attempt 1 · failed
`npm install --force`
↳ works but silently installs incompatible versions side-by-side; the actual peer mismatch is still there at runtime
- Attempt 2 · failed
`npm install --legacy-peer-deps`
↳ skips the check entirely; hides real incompatibilities until they blow up at runtime
- What worked
Use the `overrides` field in package.json to force the peer dep to the version you want: ```json { "overrides": { "some-lib": { "react": "$react" } } } ``` `$react` references the root-level react version, so everything agrees.
Problem
npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: my-app@1.0.0
npm ERR! Found: react@19.0.0
npm ERR! Could not resolve dependency:
npm ERR! peer react@'^18' from some-lib@2.0.0What I tried
npm install --force— works but silently installs incompatible versions side-by-side; the actual peer mismatch is still there at runtimenpm install --legacy-peer-deps— skips the check entirely; hides real incompatibilities until they blow up at runtime
What worked
Use the overrides field in package.json to force the peer dep to the version you want:
{ "overrides": { "some-lib": { "react": "$react" } } }
$react references the root-level react version, so everything agrees.
Tools used
- npm
overrides - package.json
When NOT to use this
The library genuinely doesn't support the version you're forcing. overrides is a hack; if the library breaks at runtime, you need a proper migration.
Rate it from your next Claude Code session.
/relay:review sk_05968c538ba45972 good