How to fix "npm error code ERESOLVE: unable to resolve dependency tree"

Tested: we reproduced this error and confirmed the fix on Ubuntu 24.04 with Node 22 and npm 10.9, November 29, 2026.

One of the packages you’re installing wants a different version of a shared dependency (usually React, Angular or a plugin’s host) than the one your project has. Install a version that matches what you already use:

npm install react-test-renderer@18

We reproduced it with npm 10.9 by adding react-test-renderer@17 to a React 18 project. npm refused with ERESOLVE unable to resolve dependency tree, and installing version 18 of the same package went through cleanly.

Read the error first

The message tells you exactly what clashes:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error Found: react@18.3.1
npm error   react@"^18.3.1" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"17.0.2" from react-test-renderer@17.0.2
npm error   react-test-renderer@"17" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry this command with --force or --legacy-peer-deps
  • Found is what your project has (react@18.3.1).
  • Could not resolve is what the new package wants (react@17.0.2) and which package wants it (react-test-renderer@17.0.2).

On npm 8 and older the lines start with npm ERR! instead of npm error. The content is the same.

Fix: install a version that matches

Check which versions of the package support what you have:

npm view react-test-renderer peerDependencies
npm view react-test-renderer versions

Then install the release built for your version, as in our test (react-test-renderer@18 alongside react@18).

Fix: upgrade or downgrade the shared package

If the package you need has no release for your version yet, the other route is to move the shared dependency to what it supports. That’s a bigger change, so check your other packages’ peer ranges first with npm ls react.

Fix: override the dependency in package.json

npm 8.3 and later let you force a version for a package’s dependencies with overrides. $react means “whatever version the root project uses”:

{
  "dependencies": {
    "react": "18.3.1",
    "react-test-renderer": "17.0.2"
  },
  "overrides": {
    "react-test-renderer": {
      "react": "$react"
    }
  }
}

In our test this installed without ERESOLVE, and npm ls react marked both entries as overridden. Unlike --legacy-peer-deps, the choice is written in package.json, so everyone who installs gets the same result. The same caution applies: you’re telling npm the mismatch is fine.

Fix: install anyway with --legacy-peer-deps

npm install react-test-renderer@17 --legacy-peer-deps

In our test this installed react-test-renderer@17.0.2 next to React 18 with no error. npm stops checking, so nothing guarantees the two work together. Use it when you know the mismatch is harmless (often a package whose peer range just hasn’t been updated), or to unblock yourself while you wait for an upstream release.

When it shows up on npm ci or in CI

If npm install worked on your machine but npm ci fails in CI, check that both use the same npm version (npm -v) and that any .npmrc with legacy-peer-deps=true is committed. A lockfile generated with --legacy-peer-deps needs the same flag to install.

Confirm it worked

npm install finishes without ERESOLVE, and npm ls <package> shows the versions you expect with no invalid or UNMET PEER DEPENDENCY lines. If the install works but your code can’t find the package at run time, see Cannot find module.

FAQ

What is the difference between --force and --legacy-peer-deps?

--legacy-peer-deps ignores peer dependency rules entirely, the way npm 6 did. --force keeps them but overrides conflicts it can't solve. Both can leave you with a package running against a version it wasn't built for.

How do I make --legacy-peer-deps the default for one project?

Run npm config set legacy-peer-deps true --location=project, or add legacy-peer-deps=true to an .npmrc file in the project root yourself. Commit the file so teammates and CI install the same way.

Is "npm warn ERESOLVE overriding peer dependency" the same error?

No. That's a warning: npm found a conflict but could still pick a version and finished the install. It's worth checking, but it doesn't stop you.