How to Fix npm ERR! ERESOLVE Peer Dependencies Conflict
In this tutorial, you'll learn about How to Fix npm ERR! ERESOLVE Peer Dependencies Conflict. We cover key concepts, practical examples, and best practices.
The Problem
You run npm install and get npm ERR! ERESOLVE unable to resolve dependency tree. npm v7+ strictly resolves peer dependencies and refuses to install when two packages require incompatible versions of the same peer dependency. This is common when a project uses React 18 but some library still expects React 17, or when multiple versions of the same package are required by different dependencies. The error typically includes a detailed tree showing exactly which packages conflict, making it possible to identify the root cause by reading the error message carefully.
Quick Fix
1. Use legacy peer dependency resolution (fastest fix)
npm install --legacy-peer-deps
This reverts to npm v6's behavior, which skips strict peer dependency validation. Use this as a temporary workaround while you fix the underlying conflict.
2. Identify the conflicting packages
npm ls
Look for packages marked with UNMET PEER DEPENDENCY or ERESOLVE in the output. The error message also shows exactly which packages conflict.
3. Update the conflicting packages
# Update to latest compatible versions
npm install react@18 react-dom@18
# Or update the library to match your setup
npm install some-library@latest
4. Use overrides to force peer dependency versions
{
"overrides": {
"react": "18.3.1",
"react-dom": "18.3.1",
"some-library": {
"react": "18.3.1"
}
}
}
Add this to package.json. Overrides let you force a specific version regardless of what sub-dependencies specify.
5. Use --force as a last resort
npm install --force
This forces the install even with peer dependency conflicts. Use carefully — it may create a broken setup.
6. Check peer dependency requirements before adding
npm view <package> peerDependencies
7. Use a dedicated overrides section
{
"overrides": {
"some-library": {
"react": "18.3.1",
"react-dom": "18.3.1"
}
}
}
Common Causes
| Conflict | Example | Fix |
|---|---|---|
| React version mismatch | Library needs React 17, project uses React 18 | npm install react@18 react-dom@18 |
| Multiple versions of same lib | Two dependencies require different versions | Use overrides to force one version |
| npm v7+ strict resolution | Code worked with npm v6 | Use --legacy-peer-deps temporarily |
| Missing peer dependency | Library expects a peer that isn't installed | Install the peer dependency |
Prevention
- Keep all major dependency versions in sync (especially React, Angular, Vue ecosystems)
- Use
npx npm-check-updatesto find outdated packages before installing new ones - Check peer dependency requirements with
npm view <package> peerDependenciesbefore adding a package
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro