Contents
A peer dependency is a package a library expects you to provide, such as React for a React component library. Since npm 7, npm installs peer dependencies itself and refuses to continue when two of them can’t agree on a version. The error text tells you exactly which versions clash.
How to read the error
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! react@"^18.3.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^17.0.0" from [email protected]
- Found is what your project already uses (React 18).
- Could not resolve names the package with the conflicting requirement (
old-datepickerwants React 17).
The fix is almost always about the package in the second block.
Causes
- A library hasn’t published a version that supports your framework’s new major version yet.
- You upgraded the framework (React, Angular, ESLint, TypeScript) but not its plugins.
- An outdated package pinned in
package.jsonblocks the upgrade. - A lock file created with old npm, installed with a newer npm.
How to fix it
-
Check whether a compatible version exists:
npm view old-datepicker peerDependencies npm view old-datepicker versions --json -
Upgrade the conflicting package to a version that accepts your framework version:
npm install old-datepicker@latest. This is the real fix. -
If no version supports it, replace the library, or keep the framework on the version it supports.
-
As a deliberate workaround, ignore peer conflicts:
npm install --legacy-peer-depsThe trade-off: npm installs a combination the library author didn’t test, which can fail at runtime (for example “invalid hook call” from two copies of React). If you rely on it, add
legacy-peer-deps=trueto an.npmrcfile in the project, sonpm cion your server and in CI resolves the same way. -
For one stubborn package, an
overridesentry inpackage.jsonis more targeted than a global flag:"overrides": { "old-datepicker": { "react": "$react" } } -
Avoid
--forceunless you understand what it overrides. -
Verify the tree with
npm ls reactand run your tests before deploying.
If the install then succeeds but the app can’t load a package, see Cannot find module.
When it fails only on the server
If npm install works on your computer but the same project fails on the server with ERESOLVE, compare the npm versions on both (npm -v) and make sure the server has the same package-lock.json and .npmrc. A lock file created with --legacy-peer-deps can’t be reproduced by a plain npm ci on a machine without that setting, so the server stops at the conflict your computer skipped.
Prevention
- Upgrade a framework together with its plugins, in a separate branch.
- Commit
package-lock.jsonand install withnpm cieverywhere. - Run installs in CI on every change, so conflicts appear before deployment.
On ArabyHost
npm behaves the same on ArabyHost AI/Developer plans as on your computer, with Node.js 20 and 24 available in cPanel’s Setup Node.js App. Commit the same package-lock.json and .npmrc you use locally so installs over SSH resolve identically. For heavy front-end projects such as Next.js, you can install and build in GitHub Actions and deploy the result with automatic deploys from GitHub.
FAQ
What's the difference between --legacy-peer-deps and --force?
`--legacy-peer-deps` ignores peer dependencies, the way npm 6 did. `--force` goes further and overrides conflicts in other places too. Both hide the problem; `--legacy-peer-deps` is the more predictable of the two.
Is it safe to use --legacy-peer-deps?
Often it works, because many libraries declare narrow peer ranges that are stricter than necessary. But nobody tested that combination, so test the affected feature carefully and plan to upgrade the package properly.
Why did this start after upgrading npm?
npm 7 and newer install peer dependencies automatically and stop on conflicts. npm 6 only printed a warning, so old projects that installed fine before can fail now.