Dependency guide
How to fix npm peer dependency conflicts (ERESOLVE)
npm 7 turned peer dependency warnings into hard errors. Here is how to read the conflict, pick the right fix — upgrade, overrides, or --legacy-peer-deps — and spot when the error is telling you something deeper about the package.
- What are peer deps
- Reading the error
- Fix strategies
- Using overrides
- --legacy-peer-deps vs --force
- React version conflicts
- When conflict = red flag
- DepCheck + peer deps
- FAQ
What are peer dependencies?
The peerDependencies field in a package’s package.json is a declaration of compatibility rather than a bundle: “I work with version X of this shared library, which the host project must provide.” A React component library declaring "peerDependencies": { "react": "^17" } is saying it expects React to be installed by the consuming project, not by the library itself.
This matters for three reasons:
- Avoids duplicates. If a library bundled its own React, you would end up with two copies of React in
node_modules, which breaks React hooks and context. - Signals compatibility. The range tells you which versions of the shared library the author has tested against.
- Creates install-time errors in npm 7+. Starting with npm 7, peer deps are automatically installed when missing, and conflicts fail the install with ERESOLVE.
--legacy-peer-deps flag restores the old npm 6 behavior.
Reading the ERESOLVE error
The error looks dense but follows a consistent pattern. Here is an annotated example:
The key lines are:
- Found: the version of the shared package already in the tree (
react@18.3.1) - peer X from Y: the version range the conflicting package requires (
react@"^17.0.2"fromsome-ui-library@2.3.0)
That is the entire conflict: your project has React 18, the library wants React 17. Everything else is context.
Fix strategies (best to worst)
1. Upgrade the conflicting package (best)
Check whether a newer version of the package supports your installed peer dependency. Run npm show some-ui-library peerDependencies --json against each version to find one with a compatible range, then bump the version in your package.json.
# See all published versions
npm show some-ui-library versions --json
# Check the peer deps of a specific version
npm show some-ui-library@3.0.0 peerDependencies
# Upgrade to the compatible version
npm install some-ui-library@3.0.0
This is the right fix when the package has an active release that supports your stack.
2. Downgrade the peer dependency (sometimes right)
If the conflicting package is critical and has no compatible release, you may need to downgrade the peer dependency instead. For example, if no version of some-ui-library supports React 18, downgrading your app to React 17 resolves the conflict. This is usually only the right call if you are locked to that library for a good reason and the upgrade path does not exist yet.
3. Use overrides to force a compatible version (npm 8.3+)
When you cannot upgrade the conflicting package or the peer dependency, use the overrides field in your root package.json to force the sub-tree to use a specific version. See overrides in detail below.
4. --legacy-peer-deps as a temporary workaround
Skips peer dependency resolution. The packages install but npm has not verified they are compatible. Safe only if the packages work at runtime with the installed versions — which you must verify by testing. See full comparison below.
5. --force as a last resort
Forces the install regardless of conflicts. Can install incompatible duplicate versions. Use only after all other options are exhausted and after extensive testing.
Using overrides (npm 8.3+)
The overrides field in your root package.json forces every resolved instance of a package to use a specific version, regardless of what individual packages declare as peer or regular dependencies. It is the most targeted way to resolve a conflict without disabling all peer dep checks:
// package.json
{
"dependencies": {
"some-ui-library": "^2.3.0"
},
"overrides": {
"some-ui-library": {
"react": "^18"
}
}
}
This tells npm: when resolving some-ui-library’s dependency tree, use react@^18 instead of whatever it declares. The library gets the React 18 instance from your tree, not a separate React 17 install.
You can also apply an override globally (to any package that requires a specific dep):
// Force ALL packages that depend on react to use ^18
"overrides": {
"react": "^18"
}
some-ui-library genuinely breaks on React 18 at runtime, forcing the version will not fix that. Always test your app after adding an override. Overrides suppress the install-time error; they do not suppress runtime breakage.
Overrides require npm 8.3.0 or later. For Yarn, the equivalent is resolutions in package.json. For pnpm, use pnpm.overrides.
--legacy-peer-deps vs --force: which to use
| Flag | What it skips | Risk level | When to use |
|---|---|---|---|
--legacy-peer-deps |
Peer dependency resolution checks only | Moderate | Package likely works with the installed version; you need to unblock CI quickly and will test manually |
--force |
Peer dep checks + other version conflict checks; can install incompatible duplicates | High | Last resort when --legacy-peer-deps still fails; requires thorough regression testing |
overrides |
Nothing — forces a specific resolution instead of skipping checks | Lower | When you want npm to resolve a specific sub-tree version without disabling all checks |
Persist your choice. If you use --legacy-peer-deps, save it in your project’s .npmrc so CI and teammates do not hit the error again:
# .npmrc
legacy-peer-deps=true
legacy-peer-deps=true in .npmrc means you never have to pass the flag again, and npm ci in CI will also use it. Commit the .npmrc so the whole team is consistent.
React version conflicts: the most common case
The most frequent peer dep conflict in 2024–2026 is a package that declares "peerDependencies": { "react": "^17" } while the project uses React 18 (or React 19). React 18’s concurrent rendering and createRoot API are backwards-compatible for most component usage, so many packages that declare a React 17 peer dep work fine on React 18 at runtime.
The decision tree for a React conflict:
- Check the package’s changelog or issues for “React 18 support” — many maintainers widened the peer dep range in a patch release without a major bump.
npm show package-name@latest peerDependenciestells you if the latest version supports React 18. - If latest already supports React 18, you are on an outdated pinned version. Upgrade.
- If no version supports React 18, the package has not been maintained for React 18. Check the last publish date and open issues count. A package with no React 18 release after 2+ years is likely unmaintained — look for an actively maintained fork or replacement.
- If you need to stay on the old package and it works at runtime, add
legacy-peer-deps=trueto.npmrcand document why.
When a peer dependency conflict is a red flag
Not every conflict is benign. A conflict can be a symptom of a deeper problem with the package:
- No release in 2+ years. If the package has not been updated since React 17 was current, it is not being maintained. Bugs and CVEs discovered since then are likely unpatched.
- Requires a very old Node version. A
"engines": { "node": "^12" }declaration combined with a stale peer dep range signals a package frozen in time. - Many open issues with no responses. Maintainer abandonment is the leading cause of peer dep conflicts that never get fixed.
- Requires a known-vulnerable peer dep version. If the conflict is that the package requires a version of a peer dep that has published CVEs, the conflict is protecting you — the right answer is to find a package that works with the patched version.
--legacy-peer-deps to paper over a security issue. If a package refuses to install because it requires a known-vulnerable version of a peer dep, the conflict is the safety rail, not the problem. Papering over it with --legacy-peer-deps installs the vulnerable version silently. Find a replacement package or force the patched peer dep version via overrides.
Using DepCheck to evaluate the conflicting package
When a peer dependency conflict points to a package you are questioning, run a DepCheck scan to see the full risk picture before deciding whether to paper over the conflict or replace the package.
DepCheck flags abandonment signals (no recent releases, deprecated status), CVEs in the package itself, typosquatting risk, and license issues — the same signals that often correlate with stale peer dependency ranges. A package that is flagged as abandoned in DepCheck is a strong candidate for replacement, not a workaround.
Check the conflicting package in DepCheck →
Paste your package.json and see CVE findings, abandonment signals, and license risk alongside the packages that are causing your peer dep conflict — no install, no account, all in the browser.
Frequently asked questions
What is an npm peer dependency conflict?
A peer dependency conflict happens when two packages in your dependency tree disagree on the required version of a shared dependency. For example, package A declares peerDependencies: { react: '>=17 <18' } while your project has React 18 installed. npm 7 and later treat this as a hard error (ERESOLVE) and refuse to install. npm 6 and earlier only printed a warning and let the install proceed.
What does ERESOLVE mean in npm?
ERESOLVE stands for a dependency resolver error — npm cannot find a version combination that satisfies all declared peer dependency constraints at the same time. The error message prints the dependency tree fragment that caused the conflict, naming the package, the version it requires, and the version that is actually present in the tree.
Is --legacy-peer-deps safe?
--legacy-peer-deps tells npm to ignore peer dependency conflicts and behave like npm 6, which only warned about them. It is safe if the packages are functionally compatible at runtime despite the version mismatch — many packages declare conservative peer dep ranges and work fine with newer major versions. It does not hide runtime errors; it only suppresses the install-time check. Test your app after using it. It is not safe if the conflict involves a genuinely breaking API change or a known-vulnerable peer dep version.
What is the difference between --legacy-peer-deps and --force?
--legacy-peer-deps skips peer dependency resolution checks only. --force skips peer dependency checks and overrides other safety checks, potentially installing incompatible duplicate versions of the same package into node_modules simultaneously, which can cause subtle runtime bugs. Use --legacy-peer-deps first; reach for --force only as a last resort when --legacy-peer-deps still fails.
How do I fix a peer dependency conflict without using --legacy-peer-deps?
The cleanest fix is upgrading the conflicting package to a version that supports your installed peer dependency. If no compatible version exists, use the overrides field in your package.json (npm 8.3+) to pin the peer dependency to a version the conflicting package can accept:
{ "overrides": { "some-package": { "react": "^18" } } }
This forces the sub-tree to use the version you specify. Always test after applying an override.
Why does the conflict only appear in CI and not locally?
If your local environment uses npm install while CI uses npm ci, they can produce different results. npm ci does a clean install from package-lock.json with stricter peer dependency enforcement. Local installs may have cached resolutions from an older npm version. A version difference in npm itself between local and CI is the most common cause. Pin the npm version in .nvmrc or the engines field and make sure CI uses the same version.
Does DepCheck flag peer dependency conflicts?
DepCheck flags the risk signals that most often cause peer dependency conflicts: abandoned packages (no releases in years), deprecated packages, and known CVEs. If DepCheck flags a package as abandoned, that is a strong signal to find a maintained replacement rather than papering over the conflict with --legacy-peer-deps. A peer dep conflict from an actively maintained package is usually just a delayed range bump by the author.
Also in the DepCheck guide library
Peer dependency conflicts are one piece of the dependency risk picture. These guides cover the rest:
Step-by-step remediation workflow: upgrade paths, overrides, and when to replace a package entirely.
Complete pre-deploy audit: CVEs, abandoned packages, license risk, and CI integration.
Tool comparison npm audit vs Snyk vs DependabotWhich scanning tool catches what, and how to combine them without redundant noise.
Supply chain npm SBOM generationGenerate a CycloneDX or SPDX software bill of materials for your npm project.
Also in the Copper Bay Labs ship-safety suite
Dependency risk is one pre-ship check. These free tools cover the rest:
Paste code or a config file and see exposed API keys and secrets before they reach the repo.
HTTP hardening HardenCheckCheck your security headers and CSP in seconds.
ADA / WCAG ShipSafeScan for ADA/WCAG failures before they become a demand letter.
Live site scan ExposureCheckScan a running URL for exposed files, secrets, and misconfigured headers.