Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm install stops with ERESOLVE because a plugin wants webpack 4 and the project uses webpack 5

Errornpm ERR! Could not resolve dependency:

Short answer

Since npm 7 peer dependencies are installed and checked. A plugin that asks for webpack ^4 conflicts with webpack 5 and npm stops with ERESOLVE. The clean fix is to drop the old plugin, because webpack 5 minimizes in production mode by itself. If you must keep it, install with legacy-peer-deps.

  • Applies to npm 10, webpack 5, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Read which package asks for the old peer and what version you have installed. Then decide whether you still need that package at all.

    npm ls webpack
  2. 2Match what you see, then jump to its fix

    1. 1uglifyjs-webpack-plugin is in package.json and the config only uses it to minify.The plugin is obsolete because webpack 5 minimizes by itselfFix
    2. 2Another tool in the build still imports the plugin and cannot be removed yet.You need the old plugin and accept an unchecked peerFix

What does the error look like?

  • npm ERR! Could not resolve dependency:
  • npm ERR! peer webpack@"^4.0.0" from uglifyjs-webpack-plugin@2.2.0

Cause 1 of 2

The plugin is obsolete because webpack 5 minimizes by itself

1Check

Minimization is on by default in production mode, using webpack's own default minimizer. A separate UglifyJS plugin adds nothing.

grep -n -E "uglify|minimizer|minimize" package.json webpack.config.*

2Fix

Uninstall the plugin and remove it from optimization.minimizer.

npm uninstall uglifyjs-webpack-plugin
# webpack.config.js: delete the UglifyJsPlugin entry, keep mode: 'production'

3Verify

Install and build in production mode; the output is minified.

npm install
npx webpack --mode production

Confirmed by webpack.js.org

Did this fix it?

Cause 2 of 2

You need the old plugin and accept an unchecked peer

1Check

legacy-peer-deps makes npm ignore peerDependencies when building the tree, as npm 3 to 6 did. The docs warn it does not enforce the peerDependencies contract.

npm config get legacy-peer-deps

2Fix

Install with the flag, or save it for this project only. Treat it as a stopgap.

npm install --legacy-peer-deps
# or keep it in the project's .npmrc
echo "legacy-peer-deps=true" >> .npmrc

3Verify

The install completes without ERESOLVE and the build still passes.

npx webpack

Confirmed by docs.npmjs.com

Did this fix it?

How do I stop it coming back?

  • Check a plugin's peer range before adding it, and avoid plugins that only support webpack 4.
  • Use the install flags above as a temporary step with a note in the repository, not as a permanent setting.
  • Run npm install in CI without the legacy flag, so a new conflict shows up early.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

ng serve says it cannot determine the project or target

Cannot determine project for command.

The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.

3 causes, each with a fix

Back end

ng serve cannot find the dev-server builder package

Could not find the implementation for builder @angular/build:dev-server

The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.