Error fixes
Fix npm ERESOLVE Unable to Resolve Dependency Tree
npm ERESOLVE means two packages in your project ask for incompatible versions of a shared dependency, usually a peer dependency, and npm refuses to guess which one wins. Read the tree in the error to find the package that pins the old version, then upgrade or align it; use --legacy-peer-deps only when you understand what it skips.
By CodingMarble · Published · 4 min read

The error you are seeing
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: my-app@1.0.0
npm ERR! Found: react@19.0.0
npm ERR! node_modules/react
npm ERR! react@"^19.0.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0 || ^17.0.0 || ^18.0.0" from some-ui-kit@2.3.1
npm ERR! node_modules/some-ui-kit
npm ERR! some-ui-kit@"^2.3.1" from the root projectThe message is long, but it is structured like a small report. The line starting with Found tells you what is already in the tree. The line starting with Could not resolve dependency tells you which package is objecting and the range of versions it accepts. In the example, your project uses a major version of React that the UI kit has not declared support for. The package names and numbers in your own error will differ, so treat the shape as the lesson.
What a peer dependency is, and why npm is strict about it
A normal dependency is something a package installs for its own private use. A peer dependency is different: the package says, in effect, "I work with this library, but you must supply it, and it must be a version I support." Component libraries declare React as a peer because two copies of React in one app break hooks and context. The package author lists the accepted range in the peerDependencies field of its package.json.
Since npm 7, peer dependencies are installed and checked automatically, and a conflict stops the install. Older npm versions only printed a warning, which is why a project that installed fine years ago can fail on a new machine with a newer Node and npm. The strictness is deliberate: a mismatched peer is a genuine risk of runtime errors, not just a cosmetic warning.
Fixing it properly, in order of preference
Start by asking which side is out of date. Run npm ls react (substitute the package from your error) to see every place it appears and which version each parent expects. Then work through these options in order.
- Upgrade the objecting package. Check whether a newer release widens its peer range. Run npm view some-ui-kit peerDependencies versions to list what each release accepts, then install a release whose range includes your version.
- Align your own version. If the library has no release for your major version yet, pin the shared dependency to a version inside its supported range, as long as the rest of your app can live with it.
- Replace the package. If it is abandoned and has no maintained fork, the long-term fix is a different library, not a flag.
- Read the package's issue tracker. Maintainers often say whether the declared range is merely conservative or the new major version truly breaks something.
Before choosing, confirm what is actually installed with npm ls, not what you remember. A second copy of a dependency nested deep in node_modules can be the real culprit, and npm dedupe or deleting node_modules and the lockfile in a throwaway branch can reveal it.
When --legacy-peer-deps and --force are acceptable
Two flags bypass the check, and they do different things. --legacy-peer-deps tells npm to ignore peer dependencies during resolution, behaving roughly like npm 4 to 6. --force goes further: it proceeds despite conflicts and may install versions that npm itself considers invalid. Neither makes the packages compatible. They only silence the checker.
Using --legacy-peer-deps is reasonable when you have read the library's changelog or tested the app and know the declared range is simply behind, for example a library whose maintainers confirm support in an unreleased version. The risk is concrete: peers that nobody installs can be missing at runtime, and a truly incompatible version fails later, in the browser, with a harder error than the one you avoided. Treat it as a documented, temporary exception, and write down why.
# .npmrc in the project root
legacy-peer-deps=truePractical tip: after any flag-based install, run your build and your tests before committing the lockfile. If the app starts and the pages that use the conflicting package render, you have evidence. If you cannot say what you tested, you have only hidden the error.
Pinning a nested version with overrides
Sometimes the conflict sits in a package you do not control, deep inside the tree. The overrides field in package.json lets you force one version of a package everywhere, or only beneath a named parent. It is more precise than a global flag because it changes one relationship instead of turning checks off.
{
"dependencies": {
"react": "^19.0.0",
"some-ui-kit": "^2.3.1"
},
"overrides": {
"some-ui-kit": {
"react": "$react"
}
}
}The $react value means "use the version I declared for react at the top level", which keeps the override from drifting. Overrides need a recent npm 8.3 or later, and Yarn and pnpm use different field names (resolutions and pnpm.overrides), so check your package manager's current documentation. An override has the same compatibility risk as a flag; its advantage is that the decision is written down in a file reviewers can see.
Lockfile hygiene and CI
Commit package-lock.json. In CI, use npm ci instead of npm install: it installs exactly what the lockfile says and fails if package.json and the lockfile disagree, which turns a quiet drift into a visible failure. If you rely on a flag, remember that CI reads the project's .npmrc but not your local command line, so a fix that works on your laptop with --legacy-peer-deps will fail in the pipeline unless the setting is committed.
To confirm the problem is fixed, delete node_modules, run a clean install, then run npm ls and look for lines marked invalid or UNMET PEER DEPENDENCY. A clean tree plus a passing build is the real test. To prevent the error returning, upgrade dependencies in small batches rather than all at once, read the peer ranges before bumping a major framework version, and keep a note of any deliberate override.
Keep reading
- Error fixesFix 'Module not found: Can't resolve' in Next.jsThe bundler tried to follow an import and could not find a matching package or file, so the build stops. Check the exact string in the error against what is installed and what exists on disk, paying attention to filename case, extensions, path aliases and whether the import runs in the browser.
- Web developmentHow to Speed Up a Next.js WebsiteMost slow Next.js sites are slow for ordinary reasons: oversized images, late-loading fonts, too much client-side JavaScript and uncached data. Fix those four in order, and measure with both Lighthouse and real-user data so you know the change helped.
- Interview questions and cheat sheetsGit Commands Cheat Sheet by TaskThis Git cheat sheet is organised by what you are trying to do, with copy-ready commands and a clear label on every command that can destroy work. It ends with the reflog, which is how most lost commits get back.
- Interview questions and cheat sheetsNode.js Interview Questions and Answers for DevelopersNode.js interviews test whether you understand one idea: a single JavaScript thread that never waits, supported by an event loop and a pool of helpers. The sixteen answers below build from that idea toward streams, concurrency, Express and the failures that show up in production.
Need this built properly for your business?
CodingMarble is a remote studio in India that builds websites, apps and games on fixed packages with the scope written down before payment. Try the free tools we run, or start a project when you are ready.