Skip to content
Latchkey

Webpack "ERESOLVE could not resolve" peer dependency at install before build in CI

Before Webpack ever runs, npm ci fails because a loader or plugin declares a peer dependency on a Webpack version that conflicts with the one in your tree. npm 7+ enforces peer ranges strictly, so the install aborts with ERESOLVE.

What this error means

The install step fails with "npm error code ERESOLVE", "Could not resolve dependency: peer webpack@... ", and a conflict between a loader/plugin and your Webpack version. The build never starts.

npm
npm error code ERESOLVE
npm error Could not resolve dependency:
npm error peer webpack@"^4.0.0" from babel-loader@8.2.5
npm error   Conflicting peer dependency: webpack@4.46.0

Common causes

A loader/plugin peer range excludes your Webpack

A loader pinned to webpack@^4 cannot coexist with webpack@5; npm 7+ refuses to build an inconsistent tree.

A mixed-major dependency bump

Webpack was upgraded but a loader or plugin was not, leaving the peer ranges incompatible.

How to fix it

Upgrade the loader/plugin to match Webpack

  1. Read which package's peer range conflicts.
  2. Install a version of that package whose peer range includes your Webpack.
  3. Commit the updated lockfile so CI installs cleanly.
Terminal
npm install babel-loader@9 webpack@5
npm ci

Use --legacy-peer-deps only as a stopgap

If you cannot upgrade immediately, this skips peer enforcement, but the underlying mismatch should still be fixed.

Terminal
npm ci --legacy-peer-deps

How to prevent it

  • Upgrade Webpack and its loaders/plugins together.
  • Commit a lockfile that resolves cleanly under npm 7+.
  • Treat ERESOLVE as a real conflict, not just noise to override.

Frequently asked questions

What causes ""ERESOLVE" webpack peer dependency"?
A loader pinned to webpack@^4 cannot coexist with webpack@5; npm 7+ refuses to build an inconsistent tree.
How do I fix "ERESOLVE" webpack peer dependency?
Upgrade the loader/plugin to match Webpack

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card