Your npm install just failed with a wall of red text that ends in ERESOLVE unable to resolve dependency tree. The fastest fix on the internet — --force or --legacy-peer-deps — is almost always the wrong one. Here is how to read the conflict and resolve it deliberately.
ERESOLVE is not a bug and it is not npm being difficult. Since npm 7 the resolver refuses to silently install a dependency tree where a stated peer dependency cannot be satisfied. That refusal is a feature: it is telling you, before anything reaches your node_modules, that two packages disagree about which version of a third package should be present. The temptation is to make the message go away. The discipline is to find out which two packages are arguing and decide, on the evidence, who is right.
Read the conflict before you touch a flag
The error output contains everything you need. It is verbose, but it is structured. A typical conflict looks like this:
Free · 4 minutes
Do you actually know what you are running — and what it is about to cost you?
Fourteen questions on the systems you depend on, the ones nobody owns, and the support dates that turn a routine upgrade into a forced re-platform. Banded finding on screen, full sheet by email.
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: my-app@1.0.0
npm error Found: react@18.3.1
npm error node_modules/react
npm error react@"18.3.1" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^17.0.0" from legacy-widget@2.1.0
npm error node_modules/legacy-widget
npm error legacy-widget@"2.1.0" from the root project
Read it from the two anchor lines. Found: tells you what is already in the tree — react@18.3.1, pulled in directly by your project. Could not resolve dependency: tells you what could not be satisfied — legacy-widget wants a peer of react@^17.0.0, and 18 does not satisfy that range. That is the entire conflict: two constraints, one on React 18, one on React 17, and no version that fits both.
A peer dependency is a package saying “I need this to exist in your tree, at this version range, but I am not going to install it myself.” It is how plugins declare compatibility with a host library. So the honest questions are: is legacy-widget simply out of date, and does a newer release support React 18? Or is React 18 genuinely fine here and the widget’s range merely conservative?
Decide: upgrade the requester or override the peer
There are only two correct resolutions, and they are decided by facts you can check in a minute.
Upgrade the requester if a compatible version exists. Run npm view legacy-widget peerDependencies and npm view legacy-widget versions. If a later release declares react@^18, the conflict is stale and the fix is to move to that version. This is always the first choice, because it resolves the disagreement rather than papering over it. The maintainer has done the compatibility work; take it.
Override the peer only when no compatible release exists but you have good reason to believe the package works with your version anyway — an open issue where the maintainer confirms it, a changelog showing no breaking React 18 usage, or your own testing. This is a judgement, and it belongs in your package.json where it is reviewable, not in a shell flag that vanishes after the install.
Use the overrides field, not a flag
The overrides field, available since npm 8.3, lets you pin what version of a nested dependency the resolver must use. To tell npm that legacy-widget should accept the React your project already declares, add this to package.json:
{
"dependencies": {
"react": "18.3.1",
"legacy-widget": "2.1.0"
},
"overrides": {
"legacy-widget": {
"react": "$react"
}
}
}
The $react reference is doing real work. It tells npm to use whatever version your root project declares for react, so the override never drifts out of step with your actual dependency. You could hard-code "react": "18.3.1" instead, but then you have two places to update on every React bump. The nested form — override react only where it appears under legacy-widget — is deliberately narrow. It does not touch any other package’s React peer, which is exactly the blast radius you want.
If you have come from the Yarn world, note that overrides is npm’s field; resolutions is Yarn’s. They solve the same problem with different syntax and are not interchangeable. Putting a resolutions block in a package installed with npm does nothing.
The value of doing it this way is that the decision is committed, diffed, and code-reviewed. Six months on, when someone asks why legacy-widget is running against a React it never officially supported, the answer is in version control rather than in a CI script nobody reads. This is the same instinct behind keeping a real record of what your build actually depends on — the argument for a bill of materials for your artefacts applies just as much to a Node dependency tree as to model weights.
When –force and –legacy-peer-deps are actually acceptable
The two flags are not equivalent, and neither belongs in a considered fix. --legacy-peer-deps tells npm to ignore peer dependencies entirely, restoring the npm 4-to-6 behaviour where peers were never auto-installed or checked. --force goes further: it overrides multiple safety checks and will happily write a broken, internally inconsistent tree to disk. Of the two, --legacy-peer-deps is the less destructive.
There is one place a flag is defensible: a quick, throwaway local reproduction to confirm whether a package even works with your version before you commit an override. Run it once, interactively, to gather evidence. What you should not do is bake either flag into your .npmrc, your Dockerfile, or your CI pipeline, because that disables the check for every dependency, forever, including the next genuine incompatibility that ships into your build silently. A flag mutes the smoke alarm for the whole building to deal with one burnt slice of toast.
Verify the tree you actually got
An override changes what npm installs, so confirm the result rather than assuming it. After re-running npm install, inspect the specific package:
$ npm ls react
my-app@1.0.0
├── react@18.3.1
└─┬ legacy-widget@2.1.0
└── react@18.3.1 deduped
The word you are looking for is deduped: a single React 18.3.1 is now shared across the tree, and legacy-widget is resolving to it. If npm ls instead prints invalid next to a package, or a second copy of React appears nested under the widget, the override did not land the way you intended and you have more work to do. Run npm ls with no argument to check the whole tree for the UNMET DEPENDENCY and invalid markers before you consider the job done.
This whole discipline — read the two constraints, prefer upgrading the requester, override narrowly and in the file, verify with npm ls — is the same patient approach that keeps any package ecosystem sane, whether you are wrangling Node peers or isolating Python CLI tools so their dependencies never collide. The flag makes the error disappear. The override makes the decision visible. Only one of those is still legible when it breaks in production.
Free interactive tool
Website compliance checklist
What your site has to do, based on what it actually does
Answer as much or as little as you like — the list builds as you go. Nothing is stored against your name and no email is required.
Everything that applies
Ordered by what to do first: legal requirements you can close quickly, then larger pieces of work, then what is expected rather than required. Not exhaustive, and not a legal audit.
Dated PDF, yours to keep or circulate.
Most technology problems are not technology problems. They are control problems.
The systems exist. The investment has been made. The question is whether leadership can understand, direct, evidence, and sustain what those systems produce. Find out where control exists — and where it only appears to.