Coding

Fix npm ERESOLVE Unable to Resolve Dependency Tree

ERESOLVE unable to resolve dependency tree means one package in your project declares a peer dependency on a version of another package that conflicts with the version you asked for. Fix it by changing one of the two versions so they agree; use npm install --legacy-peer-deps only as a temporary workaround.

The two lines that matter in the error are Found: (what you have) and Could not resolve dependency: peer ... (what some package wants).

Reproducing the error

This package.json asks for React 18 and React DOM 17. React DOM 17.0.2 declares a peer dependency on exactly [email protected]:

{
  "name": "demo-app",
  "version": "1.0.0",
  "private": true,
  "dependencies": { "react": "18.2.0", "react-dom": "17.0.2" }
}

Running npm install with npm 9.8.1 on Node 18 prints (real output, log path shortened):

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   react@"18.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.2" from [email protected]
npm ERR! node_modules/react-dom
npm ERR!   react-dom@"17.0.2" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! For a full report see:
npm ERR! C:\Users\alex\AppData\Local\npm-cache\_logs\...-eresolve-report.txt

How to read the ERESOLVE message

  • While resolving: [email protected]: the package whose tree npm was building. Usually your project.
  • Found: [email protected] and react@"18.2.0" from the root project: what is already decided, and who decided it. Here, your own package.json.
  • Could not resolve dependency: peer react@"17.0.2" from [email protected]: the requirement that clashes. [email protected] says "I must be used alongside react 17.0.2".
  • react-dom@"17.0.2" from the root project: why that package is in your tree at all. If this line names another package instead of the root project, the conflict comes from a transitive dependency, and that intermediate package is the one to upgrade.

Peer dependencies exist for plugins and companion libraries that must share one copy of a host package (a React component library, an ESLint plugin, a Webpack loader). As of npm 7, the npm docs say peer dependencies "are installed by default", and a conflict is an error. npm 3 to 6 only printed a warning, which is why old projects often hit ERESOLVE the first time someone installs them with a newer npm.

Fix 1: make the versions agree (the real fix)

Look up which peer range each version of the complaining package accepts:

npm view [email protected] peerDependencies
npm view [email protected] peerDependencies

Output:

{ react: '17.0.2' }
{ react: '^18.2.0' }

React DOM 18.2.0 accepts React 18, so upgrading it resolves the conflict:

npm install [email protected]
added 5 packages in 2s

Then confirm the tree:

npm ls
[email protected] C:\work\demo-app
+-- [email protected]
`-- [email protected]

In real projects the clash is usually a plugin that hasn't caught up with a major release of its host. Run npm view <plugin> versions and npm view <plugin>@latest peerDependencies; a newer plugin release often widens the peer range. If no release supports your host version yet, the other direction works too: pin the host to the newest version the plugin supports.

Fix 2: --legacy-peer-deps (workaround)

npm install --legacy-peer-deps

The npm docs describe this flag as causing npm "to completely ignore peerDependencies when building a package tree, as in npm versions 3 through 6". In the reproduction it installed without complaint and npm ls showed [email protected] next to [email protected], a combination its authors never declared as supported. Whether that works at run time is now your problem.

If you do rely on it, make it consistent: add legacy-peer-deps=true to the project's .npmrc and commit it. Otherwise your machine installs and the next person's, or CI's, plain npm install or npm ci fails. npm ci in particular installs strictly from package-lock.json and exits with an error if the lockfile and package.json disagree.

Fix 3: --force (last resort)

npm install --force

With --force, npm still evaluates peer dependencies but overrides the conflict in the root project. Real output starts like this:

npm WARN using --force Recommended protections disabled.
npm WARN ERESOLVE overriding peer dependency
npm WARN While resolving: [email protected]
npm WARN Found: [email protected]

The resulting tree was the same as with --legacy-peer-deps. The difference is that --force also turns off other safeguards (the first warning line says so), and the npm config docs say: "If you don't have a clear idea of what you want to do, it is strongly recommended that you do not use this option!" Prefer --legacy-peer-deps over --force when you need a workaround.

Fix 4: overrides (targeted, recorded in package.json)

When one specific package has an outdated peer range and you have checked that it works with your version, an overrides entry fixes just that edge of the tree. The npm docs say overrides "provide a way to replace a package in your dependency tree with another version", and are only read from the root package.json. A value starting with $ reuses the version spec of one of your direct dependencies:

{
  "dependencies": { "react": "18.2.0", "react-dom": "17.0.2" },
  "overrides": {
    "react-dom": { "react": "$react" }
  }
}

This tells npm: inside react-dom, use whatever react the root project uses. In the test project, npm install then succeeded with no flags, and npm ls --all marked both packages as overridden:

[email protected] C:\work\demo-app
+-- [email protected] overridden
| +-- [email protected]
| +-- [email protected]
| +-- [email protected] deduped
| `-- [email protected]
`-- [email protected] overridden

Unlike a flag, the override is in package.json, so everyone gets the same tree and the decision is visible in code review. It still ships a combination the package authors did not declare, so remove the override once an upstream release fixes the peer range.

Which fix to use

OptionWhat changesUse when
Change a versionThe conflict goes awayA compatible version exists (most cases)
overridesOne peer requirement is replaced, recorded in package.jsonYou've confirmed one package works despite its stated range
--legacy-peer-depsAll peer checks are skippedTemporary unblock while you upgrade
--forceConflicts overridden, other safeguards disabledRarely; prefer the options above

If it still fails

Open the eresolve-report.txt file named at the end of the error: it lists every package involved in the conflict, which helps when the chain is several levels deep. Delete node_modules and package-lock.json only as a deliberate step, since regenerating the lockfile can also upgrade unrelated packages within their ranges; commit the new lockfile if you do. Check npm config get legacy-peer-deps too: a global or user-level setting of true can hide the error on one machine and not on another. If you only wanted to run a one-off command-line tool rather than add a dependency, you may not need to install it into the project at all: npm vs npx explains running it from the npm cache instead.

Frequently asked questions

Is --legacy-peer-deps safe?
It installs, but npm stops checking peer dependencies entirely, the way npm 3 to 6 behaved. If the versions really are incompatible, the error moves from install time to run time. Use it as a stopgap while you upgrade the package that has the outdated peer range, not as a permanent fix.
What is the difference between --force and --legacy-peer-deps?
--legacy-peer-deps ignores peerDependencies when building the tree. --force keeps checking them but lets conflicting peer dependencies be installed in the root project anyway, printing an 'ERESOLVE overriding peer dependency' warning, and it also disables other npm safety checks. npm's own docs strongly recommend against --force unless you know exactly why you need it.
Why did ERESOLVE appear after upgrading npm?
Since npm 7, peerDependencies are installed and checked by default. A project that installed fine on npm 6, which only warned about peer mismatches, can fail with ERESOLVE on npm 7 or later without any change to package.json.
How do I make the fix stick for everyone on the team?
Prefer a real version fix in package.json. If you must use legacy-peer-deps, put legacy-peer-deps=true in the project's .npmrc and commit it, so every install and CI run behaves the same, and commit the regenerated package-lock.json.

Sources