The ERESOLVE error occurs when npm 7+ encounters conflicting peer dependency requirements. Use --legacy-peer-deps for a quick fix, or resolve the underlying version conflicts for a permanent solution.
npm 7 introduced strict peer dependency resolution that fails when packages declare incompatible peer dependency requirements. This is a significant change from npm 6, which only warned about peer dependency conflicts. The error occurs when npm cannot find a version of a package that satisfies all peer dependency constraints in your dependency tree. For example, if package A requires React 17 and package B requires React 18, npm cannot satisfy both requirements simultaneously and throws ERESOLVE.
Revert to npm 6 peer dependency behavior:
# For single install
npm install --legacy-peer-deps
# For specific package
npm install package-name --legacy-peer-depsThis ignores peer dependency conflicts and proceeds with installation.
Add to .npmrc for project-wide setting:
# Create or edit .npmrc in project root
echo "legacy-peer-deps=true" >> .npmrcNow all npm install commands will use legacy resolution.
Bypass all safety checks (use with caution):
npm install --forceWarning: This may install incompatible versions that cause runtime errors.
Sometimes conflicts arise from corrupted lockfile state:
# Remove cached dependency state
rm -rf node_modules package-lock.json
# Reinstall fresh
npm install
# Or with legacy peer deps
npm install --legacy-peer-depsFor a proper fix, identify the conflicting packages:
# See outdated packages
npm outdated
# Check what versions are available
npm view package-name versions
# Update the conflicting package
npm install package-name@latestUpdate packages to versions compatible with your framework version.
Force specific versions using package.json overrides:
{
"overrides": {
"react": "^18.2.0"
}
}This tells npm to use React 18 everywhere, regardless of peer dependency declarations.
Yarn often handles peer dependencies more gracefully:
# Install Yarn
npm install -g yarn
# Remove npm artifacts
rm -rf node_modules package-lock.json
# Install with Yarn
yarn installYarn uses a different resolution algorithm that may avoid the conflict.
Using --legacy-peer-deps or --force masks underlying compatibility issues. Packages installed may conflict at runtime, causing duplicate package instances, incorrect behavior, or hard-to-debug errors. For production applications, investigate and resolve the root cause.
Common scenarios requiring this fix:
- Upgrading React 17 → 18 with packages not yet supporting React 18
- Angular major version upgrades
- Using beta/release candidate versions of frameworks
- Older packages no longer maintained
For CI/CD, add legacy-peer-deps=true to .npmrc in the repository, or modify install commands. GitHub Actions example:
- run: npm ci --legacy-peer-depsnpm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm
npm error code E403 npm error 403 Forbidden - PUT https://registry.npmjs.org/<package>
How to fix 'E403 Forbidden' error in npm
npm ERR! code EUSAGE npm ERR! Usage error
How to fix "npm ERR! code EUSAGE" in Node.js projects
npm ERR! code E401 npm ERR! 401 Unauthorized
How to fix "E401 Unauthorized" in npm