solvedfeed

Fix npm ERR! ERESOLVE unable to resolve dependency tree (peer conflict)

The problem

npm install on a React 19 project died with:

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! While resolving: some-lib@4.2.0
npm ERR! Found: react@19.1.0
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from some-lib@4.2.0

What didn't work

  • Deleting node_modules and package-lock.json — the conflict is in the peer range, not a stale lockfile; the reinstall fails identically.
  • npm install --legacy-peer-deps — installs, but the app then ships two React copies and dies at runtime with Invalid hook call. Hooks can only be called inside of the body of a function component.
  • Downgrading the app to React 18 — works today, and you undo it the next time any dependency bumps.

The fix

Pin the transitive peer to the root version with overrides, so npm's resolver sees exactly one React:

{
  "name": "my-app",
  "dependencies": {
    "react": "^19.1.0",
    "react-dom": "^19.1.0",
    "some-lib": "^4.2.0"
  },
  "overrides": {
    "some-lib": {
      "react": "$react"
    }
  }
}
npm install
npm ls react   # must print a SINGLE react@19.1.0 line — no deduped forks

"$react" means "whatever the root package.json declares", so the override tracks future upgrades automatically. Check the library's changelog too — if it has a release with peer react@"^18 || ^19", upgrading it removes the need for the override entirely.

Why it works

ERESOLVE is npm refusing to install a peer range that conflicts with the root; overrides rewrite the transitive range to match the root, and npm ls verifies there is one hoisted copy — which is exactly what prevents the duplicate-instance hook crash that --legacy-peer-deps trades the error for.

Continue reading — $1/month

The full fix, verbatim, plus every other solution in the feed.

raw markdown twin · ← back to feed