Reading and Fixing an ERESOLVE Peer Dependency Conflict

Since npm 7, peer dependencies are installed automatically and conflicts between them stop the install with an ERESOLVE unable to resolve dependency tree error. The message is long, but it has a fixed structure, and once you can read it you can tell in a minute whether you are looking at a problem in your project, in one of your dependencies, or in a package you maintain.

Reading the message

A typical report has three parts. Here is a shortened, illustrative version:

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! Found: framework-x@3.0.0
npm ERR!   framework-x@"^3.0.0" from the root project
npm ERR! Could not resolve dependency:
npm ERR! peer framework-x@"^2.0.0" from plugin-y@1.8.2
npm ERR!   plugin-y@"^1.8.0" from the root project

Translated: you asked for framework-x 3, but plugin-y 1.8.2 declares it only works with framework-x 2.

Deciding where the fix belongs

SituationWhat it suggestsAction
A newer plugin-y exists whose peer range includes framework-x 3You are on an old pluginUpgrade plugin-y
No such version, plugin-y is maintainedThe plugin has not caught upCheck its issues for a tracking ticket; stay on framework-x 2 for now
plugin-y works fine with 3 in your testingThe peer range is too narrowUse an overrides entry as a temporary measure, and tell the maintainer
You maintain plugin-yYour range is the problemTest against the new major and widen the range in a release

About the escape hatches

npm install --legacy-peer-deps tells npm to ignore peer dependencies the way npm 6 did. It makes the error disappear, and it also makes npm stop installing any peers automatically, which can hide real incompatibilities. --force goes further and accepts a broken tree. Both are reasonable for a one-off experiment and poor as a permanent setting in .npmrc.

A narrower option is overrides in your root package.json, which changes the resolution for one package while leaving the rest of the checks in place:

{
  "overrides": {
    "plugin-y": {
      "framework-x": "$framework-x"
    }
  }
}

The $framework-x reference tells npm to use the version your root project depends on. Leave a comment in your pull request or a ticket explaining why it is there, so it gets removed when the plugin catches up.

If you are the package author

Conflicts reported against your package are usually a sign that your peer range is either narrower than what you actually support, or wider than what you test. Keep it honest: list every major you run tests against, and add a new major only after a test run passes on it. Widening a peer range is normally a minor change; narrowing it can break existing installs, so many maintainers treat it as major. The peer dependencies guide explains the model and the peer range change case study shows a narrowing that went wrong. If you still cannot see why the tree fails, npm explain framework-x prints every path that requires it, which is the clearest picture short of asking the maintainers involved.