Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new

npm ERR! code ERESOLVE unable to resolve dependency tree: how to fix it

npm ERR! code ERESOLVE, unable to resolve dependency tree (npm error ERESOLVE in newer npm) means two packages in your project need versions of a shared peer dependency that cannot both be met. Since npm 7 installs peer dependencies, it stops instead of guessing. The real fix is to make the versions match: upgrade the package that is behind, or use the version it supports. --legacy-peer-deps and --force only skip the check.

By Livops team, the people who build and run LivopsUpdated

The error as current npm prints it (shortened; @acme/date-picker stands for any package with a peer dependency)[6][8][9]:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error   react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^17.0.0 || ^18.0.0" from @acme/[email protected]
npm error node_modules/@acme/date-picker
npm error   @acme/date-picker@"^2.4.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry this command with --force or --legacy-peer-deps to accept an incorrect (and potentially broken) dependency resolution.

npm 10.5 and earlier print the same lines with npm ERR! in front[10][11]; from npm 10.6 the prefix is the heading npm and the level, error[12][13]. A variant says ERESOLVE could not resolve instead; it is the same conflict, found at a different step[7]. This page explains what a peer dependency is, why npm 7 and later stop on it, the real fix, and when the two flags in the message are acceptable.

What does the error mean?

Peer dependencies

A plugin often works with a host package without importing its own copy of it. It says so in peerDependencies: npm’s example is @npm/tea-latte declaring "@npm/tea": "2.x", so it can only be installed alongside the second major version of @npm/tea[1].

Why npm 7 and later stop

In npm 3 to 6, peer dependencies were not installed, and a wrong version only printed a warning. As of npm 7 they are installed by default, and npm’s docs say that a plugin with a conflicting requirement may cause an error if the tree cannot be resolved[1]. That error is ERESOLVE: npm throws unable to resolve dependency tree with the code ERESOLVE[6], and prints a report of what it found[8][9]. That is why a project that installed fine with an old npm can fail with a new one.

Not every conflict is fatal. Conflicts deep in the tree are resolved with the nearest non-peer version and a warning, ERESOLVE overriding peer dependency[2][7]. Setting strict-peer-deps turns those warnings into failures too[2].

How to read the report

The report has the same parts every time[9]:

  • While resolving — the package npm was working on.
  • Found — the version that is already in the tree, and who asked for it. Above, [email protected], requested by your own package.json (“the root project”).
  • Could not resolve dependency — the requirement that does not fit: @acme/[email protected] wants react 17 or 18.
  • Conflicting peer dependency (when present) — the peer version that clashes with what is already there.

So the example reads: your project asks for React 19, and the date picker only supports React 17 and 18. npm also writes the full report, without the depth limit, to a file ending in eresolve-report.txt[8][9].

The real fix: make the versions match

The flags in the message accept a resolution that npm itself calls incorrect and potentially broken[9]. The fix that makes the error go away for good is a set of versions that agree.

1. Upgrade the package that is behind

Usually the plugin has a newer release that supports your host version. Check what each release accepts with npm view, which takes a version and a field name[5]:

npm view @acme/date-picker versions
npm view @acme/date-picker@latest peerDependencies

If the latest release accepts react 19, install it and commit both files:

npm install @acme/date-picker@latest
git add package.json package-lock.json

2. Or use the host version the plugin supports

If no release of the plugin supports the new major yet, stay on the version it does support until one does. In the example, that is React 18:

npm install react@18 react-dom@18

3. Find who wants what

In a larger tree the conflicting package may not be in your package.json at all. npm explain (also npm why) prints the chain of dependencies that causes a package to be installed[4]:

npm explain react

Upgrade the package at the top of the chain that pulls in the old requirement.

4. Override a version you have tested

When you have checked that the plugin works with the newer host, and only its declared range is behind, overrides in the root package.json replaces a package’s version anywhere in the tree[1]. Overrides are read only from the root package.json, not from dependencies or workspaces[1].

You cannot override a package you also depend on directly unless both use exactly the same spec, or npm throws EOVERRIDE. The documented way around it is a $ reference to your own dependency’s spec[1]:

{
  "dependencies": {
    "react": "^19.0.0",
    "@acme/date-picker": "^2.4.0"
  },
  "overrides": {
    "react": "$react"
  }
}

Overrides can also be limited to one parent package, or nested deeper[1]. Run npm install afterwards and commit the lockfile. An override is a promise that you tested the combination; remove it when the plugin catches up.

The workarounds: –legacy-peer-deps and –force

Both make the install pass without changing a single version. Use them knowing what they do.

Flag What it does Risk
--legacy-peer-deps Ignores peerDependencies completely when building the tree, as npm 3 to 6 did[2] Peer requirements are not enforced; npm does not recommend it[2]
--force Removes many protections; one of them allows conflicting peer dependencies in the root project[2] Also skips engines checks and more; npm strongly recommends against it unless you know exactly why[2]
--strict-peer-deps The opposite: every peer conflict fails, even deep ones[2] Stricter installs; when it is on, the message also suggests --no-strict-peer-deps[9]

Of the two, --legacy-peer-deps changes less, because --force turns off a whole list of unrelated checks[2]. Either way, the app may break at runtime exactly where the peer requirement said it would.

Make it the same on every machine: .npmrc

A flag typed on your laptop is not used by CI or the server. npm reads a per-project config file, .npmrc next to package.json, written as key = value lines[3]. The config key is legacy-peer-deps[2]:

legacy-peer-deps=true

Commit it, so every npm install in the project, on any machine, runs with the same setting, and delete it once the versions match.

How to confirm the fix locally

Install the way a server does, from a clean tree and the committed lockfile:

rm -rf node_modules
npm install          # must finish without ERESOLVE
git status           # commit package.json, package-lock.json and .npmrc if they changed
rm -rf node_modules
npm ci

To check with the server’s Node and npm rather than yours, run the same in a container, for example docker run --rm -v "$PWD":/app -w /app node:22 npm ci.

On Livops

  • Where it shows. A failed install stops the deploy as install_failed; the error itself is in the build log, and the previous version keeps running. See Install failed.

  • A Tip line for ERESOLVE. When the log says ERESOLVE, it ends with a Tip: line for this case: fix package.json, or set Settings → Install to npm install --legacy-peer-deps. Fixing the versions is the better of the two, for the reasons above.

  • Set the install yourself. The same command can live in livops.json at the root of the repository or the project folder. install is applied on every deploy, and while the file names it, the file wins over the cabinet:

    {
      "install": "npm install --legacy-peer-deps"
    }

    A committed .npmrc with legacy-peer-deps=true works without changing the command, because npm reads it itself.

  • The assistant explains. Next to the failed build, the assistant’s button reads the log and tells you what happened and how to fix it. See AI assistant.

If the install gets past dependency resolution but fails compiling a package, see gyp ERR! build error: node-gyp rebuild failed; for other failures that end in code 1, see npm error code 1.

Questions

What does ERESOLVE unable to resolve dependency tree mean?

npm could not build one tree of packages that satisfies every version range in it. Almost always it is a peer dependency: a plugin says it works with, for example, react 17 or 18, while your project asks for react 19. npm 7 and later install peer dependencies, so they have to fit.

Is --legacy-peer-deps safe?

It makes npm ignore peer dependencies completely, as npm 3 to 6 did. npm's own docs say it is not recommended, because packages may rely on the peer contract. It is acceptable as a stopgap when you have checked that the combination works, and better than --force, which removes many other protections too.

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

--legacy-peer-deps only changes how peer dependencies are handled: they are ignored. --force removes a whole list of safety checks, one of which allows conflicting peer dependencies in the root project. npm's error message says either one accepts an incorrect and potentially broken resolution.

Why did npm install work before and fail now?

In npm 3 to 6 peer dependencies were not installed and a wrong version only printed a warning. Since npm 7 they are installed, so a conflict that used to be a warning now stops the install.

How do I make --legacy-peer-deps apply everywhere?

Put legacy-peer-deps=true in a .npmrc file in the project root and commit it. npm reads that per-project file on every machine, so your laptop, CI and the server install the same way. Remove it once the versions match.

Should I delete package-lock.json to fix ERESOLVE?

No. The conflict is between the version ranges packages declare, not in the lockfile, so a fresh lockfile usually hits the same conflict. Change the versions that disagree instead.

Sources

  1. npm Docs — package.json (peerDependencies, overrides) (docs.npmjs.com). Checked .
  2. npm Docs — config (legacy-peer-deps, strict-peer-deps, force) (docs.npmjs.com). Checked .
  3. npm Docs — .npmrc (docs.npmjs.com). Checked .
  4. npm Docs — npm explain (docs.npmjs.com). Checked .
  5. npm Docs — npm view (docs.npmjs.com). Checked .
  6. npm source — workspaces/arborist/lib/arborist/build-ideal-tree.js (github.com). Checked .
  7. npm source — workspaces/arborist/lib/place-dep.js (github.com). Checked .
  8. npm source — lib/utils/error-message.js (github.com). Checked .
  9. npm source — lib/utils/explain-eresolve.js (github.com). Checked .
  10. npm 10.5.2 source — lib/utils/display.js (raw.githubusercontent.com). Checked .
  11. npmlog source — lib/log.js (github.com). Checked .
  12. npm 10.6.0 source — lib/utils/display.js (raw.githubusercontent.com). Checked .
  13. npm source — workspaces/config/lib/definitions/definitions.js (heading) (github.com). Checked .

Put your project online today

Connect GitHub or drop a folder. No card is asked for.

Deploy your Node app

Got a question? — @livops_uz