Triage a peerDependency conflict: find the pair that collides
In one line: When no version satisfies every peer requirement, how to find the conflicting pair, compute the intersection and choose a fix.
When a tool says two packages want incompatible versions of the same library, check three things: which two constraints collide, what each one really allows, and whether any candidate satisfies both.
Step 1: expand the constraints
Peer requirements are usually carets. Expand them first, because carets behave differently at 0.x.
A: ~16.20.0 → >=16.20.0 <16.21.0 B: ^18.2.0 → >=18.2.0 <19.0.0 C: >=17 <19 → >=17.0.0 <19.0.0
A and B do not overlap at all: A ends at 16.21.0 while B starts at 18.2.0. C overlaps B but not A.
Step 2: compute the intersection
The intersection of two intervals is "the larger lower bound up to the smaller upper bound". If the lower bound is at or above the upper bound (respecting inclusivity), the intersection is empty. This tool prints the expanded interval for each constraint and lists the colliding pairs separately.
Step 3: decide in order
- Check the newest releases: if one package has already moved to the other major, an update settles it.
- Read the peer range precisely:
^18.2.0is really>=18.2.0 <19, so it can never meet a package that requires 19. - Duplicate installs: for regular dependencies npm installs both versions; for peers you get a warning or a failure instead.
- Force one version: npm
overrides, yarnresolutions, pnpmpnpm.overrides. Verify runtime compatibility afterwards. - Replace or fork: last resort, e.g. a fork with a wider peer range or a different library.
What this tool does not decide
An empty intersection is a necessary condition for an install failure, not a sufficient one: runtime compatibility and API differences are outside its scope. Without a candidate list it judges on the stable-version interval only, and PEP 440 conditions that intervals cannot express (!=, .*) need a candidate list.
Worth recording
- The two packages and their peer ranges, expanded to bounds
- Whether any common candidate existed, and which bound split them
- The fix you chose (update, override, fork) and why
Open the "peer dependency clash" preset on this page to reproduce the example above, then copy the Markdown report into an issue or pull request.
Paste the same constraints and candidate versions into this page to see which versions survive.
Open SemVerLabFrequently asked questions
Does a peer conflict block installation?
Since npm 7 it usually fails the install. --legacy-peer-deps bypasses it but leaves the runtime risk.
Is forcing a version with overrides safe?
It makes install and build pass, but it does not prove API compatibility. Run your tests against the forced version.
Can two 0.x versions of the same library coexist?
Regular dependencies can. Types and shared state usually do not, so watch for duplicate instances.
Sources
Read next
- The npm
^0.xtrap: why 0.3.0 falls outsideWhy^0.2.3ends at<0.3.0-0, how node-semver builds that bound, and which range to use for 0.x dependencies. - Cargo's
0.0.xand0.x: the patch is the boundaryWhy a bare version in Cargo means caret, why^0.0.3accepts only 0.0.3, and how commas and the missing||work. - PEP 440
~=with post and dev: three rules in one operatorHow~=1.4.2computes its upper bound, how dev/pre/post order, and what epochs, local versions and.*do.