How to fix npm ERR! code ERESOLVE npm ERR! While resolving workspace dependencies in npm

npmINTERMEDIATEHIGHUpdated Dec 7, 2025· 199 views

This error occurs when workspace packages have conflicting dependency versions. npm 7+ enforces peer dependency resolution strictly, causing failures when workspaces require different versions of the same package.

Quick fix

Fixes npm ERR! code ERESOLVE npm ERR! While resolving workspace dependencies

npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: workspace-a@1.0.0
npm ERR! Found: react@17.0.2
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from workspace-b@1.0.0
  1. Understand the conflict
  2. Align dependency versions (recommended)
  3. Use overrides to force a version
  4. Use --legacy-peer-deps (temporary fix)
npm — error
npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: workspace-a@1.0.0
npm ERR! Found: react@17.0.2
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from workspace-b@1.0.0
npm ERR! code ERESOLVE
npm ERR! While resolving workspace dependencies

What this error means

The ERESOLVE error in workspaces means npm can't find a single version of a package that satisfies all workspace requirements. Since npm 7, peer dependencies are automatically installed and strictly validated. In a monorepo, if workspace-A needs `react@17` and workspace-B needs `react@18`, npm can't satisfy both because workspaces share a common node_modules at the root. This "hoisting" strategy requires version alignment. This is different from npm 6, which just warned about conflicts but continued installation.

Typical symptoms

  • npm install fails with 'ERESOLVE unable to resolve dependency tree'
  • Error mentions 'While resolving workspace dependencies'
  • Conflicting peer dependency warnings
  • Shows two packages needing different versions
  • Worked with npm 6 but fails with npm 7+

Common causes

  1. Workspace packages requiring different versions of the same dependency
  2. Peer dependency conflicts between packages
  3. Outdated packages with strict peer dependency ranges
  4. Mixing packages designed for different framework versions
  5. Missing version alignment across workspaces

How to fix "npm ERR! code ERESOLVE npm ERR! While resolving workspace dependencies"

1Understand the conflict

Read the error output carefully—it shows exactly what conflicts:

bash
npm ERR! ERESOLVE could not resolve
npm ERR! While resolving: workspace-a@1.0.0
npm ERR! Found: react@17.0.2
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^18.0.0" from workspace-b@1.0.0

This tells you workspace-b needs react@18 but workspace-a has react@17.

2Align dependency versions (recommended)

The best fix is to use the same version everywhere. Update all workspace package.json files:

json
// packages/workspace-a/package.json
{
  "dependencies": {
    "react": "^18.0.0"
  }
}

// packages/workspace-b/package.json
{
  "dependencies": {
    "react": "^18.0.0"
  }
}

Or define shared dependencies in the root package.json.

3Use overrides to force a version

Force all packages to use a specific version using overrides in root package.json:

json
{
  "overrides": {
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  }
}

Then reinstall:

bash
rm -rf node_modules package-lock.json
npm install

This tells npm to use react@18.2.0 regardless of what individual packages request.

4Use --legacy-peer-deps (temporary fix)

Revert to npm 6's permissive behavior:

bash
npm install --legacy-peer-deps

To make it permanent for the project, add to .npmrc:

bash
legacy-peer-deps=true

Warning: This hides real conflicts that might cause runtime issues.

5Use --force (last resort)

Force installation despite conflicts:

bash
npm install --force

Warning: This can install incompatible versions and cause runtime errors. Only use when you understand the implications.

6Centralize dependencies in root

Move shared dependencies to the root package.json to ensure single versions:

json
// Root package.json
{
  "dependencies": {
    "react": "^18.2.0",
    "lodash": "^4.17.21"
  },
  "workspaces": ["packages/*"]
}

Workspaces automatically inherit root dependencies through hoisting.

Advanced notes

Why npm 7+ is stricter: npm 6 treated peer dependencies as suggestions. npm 7+ automatically installs them and validates compatibility. This catches real bugs but breaks some legacy setups.

Hoisting in workspaces: npm workspaces hoist shared dependencies to the root node_modules. This is efficient but requires version alignment. If you need different versions, consider using separate non-workspace packages.

Override specificity: Overrides can be scoped:

json
{
  "overrides": {
    "workspace-a": {
      "react": "^17.0.0"
    },
    "workspace-b": {
      "react": "^18.0.0"
    }
  }
}

This is complex and can lead to runtime issues—prefer aligning versions instead.

npm ci behavior: If package-lock.json was generated with --legacy-peer-deps, you must use that flag with npm ci too, or regenerate the lockfile.

Frequently asked questions

What does "npm ERR! code ERESOLVE npm ERR! While resolving workspace dependencies" mean?
The ERESOLVE error in workspaces means npm can't find a single version of a package that satisfies all workspace requirements. Since npm 7, peer dependencies are automatically installed and strictly validated. In a monorepo, if workspace-A needs react@17 and workspace-B needs react@18, npm can't satisfy both because workspaces share a common node_modules at the root.
How do I fix "npm ERR! code ERESOLVE npm ERR! While resolving workspace dependencies"?
This error occurs when workspace packages have conflicting dependency versions. npm 7+ enforces peer dependency resolution strictly, causing failures when workspaces require different versions of the same package.
What causes "npm ERR! code ERESOLVE npm ERR! While resolving workspace dependencies"?
Workspace packages requiring different versions of the same dependency Peer dependency conflicts between packages Outdated packages with strict peer dependency ranges
Is the "npm ERR! code ERESOLVE npm ERR! While resolving workspace dependencies" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading