opyebSemVerLab

Triage a peerDependency conflict: find the pair that collides

Dependency conflicts · 8 min read

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

  1. Check the newest releases: if one package has already moved to the other major, an update settles it.
  2. Read the peer range precisely: ^18.2.0 is really >=18.2.0 <19, so it can never meet a package that requires 19.
  3. Duplicate installs: for regular dependencies npm installs both versions; for peers you get a warning or a failure instead.
  4. Force one version: npm overrides, yarn resolutions, pnpm pnpm.overrides. Verify runtime compatibility afterwards.
  5. 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 SemVerLab

Frequently 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