ERESOLVE unable to resolve dependency tree during peerDependency installation
0 reputation · 24 Jul 2024, 23:57 UTC
0 reputation · 24 Jul 2024, 23:57 UTC
In npm version 7 and later, the package manager automatically installs peerDependencies by default. This shift from the version 6 behavior introduces a strict resolution process where the dependency graph must be fully compatible before installation can proceed.
A conflict arises when two or more dependencies require different, non-overlapping version ranges of the same peer dependency. When the resolver cannot find a single version that satisfies all constraints, the installation fails to prevent potential runtime incompatibilities.
While flags like --legacy-peer-deps or --force can bypass this failure, they introduce uncertainty regarding dependency integrity and the potential for duplicate package instances in node_modules.
30275 reputation · 25 Jul 2024, 07:32 UTC
In npm 7 and later, every peerDependency declared by any package in the tree is treated as an equal constraint. The resolver attempts to find a single version that satisfies all declared ranges simultaneously. It does not rank one package’s requirement above another’s, nor does it pick the highest or lowest version automatically. If the intersection of all ranges is empty, the install aborts with an ERESOLVE error and lists the conflicting ranges.
npm ls <peer-package-name> to see every dependent and the version range each one requires.package.json (or the dependent packages you control) so that the peer dependency version you pin falls inside every required range. This may mean upgrading or downgrading one of the conflicting packages until their ranges overlap.dependencies (or devDependencies) so npm installs that exact version and satisfies all peers.npm dedupe to collapse any duplicate copies, then npm audit to ensure no vulnerabilities were introduced.Only if the above steps cannot produce an overlapping range should you consider a temporary bypass:
npm install --legacy-peer-deps – installs without enforcing peer constraints.npm audit and npm dedupe.Missing diagnostic detail: Provide the name of the peer dependency and the exact conflicting version ranges shown in the ERESOLVE output. That information determines whether a simple version pin will resolve the issue or if a deeper upgrade/downgrade is required.
Use comments to ask for clarification. Post a solution as an answer.
30,275 reputation · 25 Jul 2024, 08:23 UTC
Since npm 8.3, the overrides field in package.json lets you force a specific version of a transitive peer dependency across the entire tree without editing dependent packages directly. This is often cleaner than --legacy-peer-deps because it preserves a single copy in node_modules.
For projects where peer conflicts recur, pnpm enforces a stricter, non-flat node_modules layout that makes version mismatches visible earlier. Its pnpm install --strict-peer-dependencies mode fails fast on any unsatisfied peer, and pnpm why <pkg> traces the exact dependency path causing the conflict.
Verification: After applying overrides or switching managers, run npm ls <peer-pkg> (or pnpm ls <peer-pkg>) to confirm a single resolved version satisfies all peers, then npm dedupe / pnpm dedupe to collapse duplicates.