Crystal
Crystal

Reputation: 141

npm install error while use webpack, Could not resolve dependency

The error as follows:

> npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"^3.5.6" from the root project
npm ERR!   peer webpack@"2 || 3 || 4" from [email protected]@[email protected]
npm ERR!   node_modules/[email protected]@babel-loader
npm ERR!   5 more ([email protected]@html-webpack-plugin, ...)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^2.0.0" from [email protected]@[email protected]
npm ERR! node_modules/[email protected]@strip-pragma-loader
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /home/agou-ops/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/agou-ops/.npm/_logs/2021-04-12T02_49_11_062Z-debug.log

debug.log file content: enter image description here

packge version and system

How should I fix it?

Upvotes: 12

Views: 43096

Answers (4)

Yasar Whizz
Yasar Whizz

Reputation: 17

For npm v7+. It is due to missing dependencies for entries mentioned in the package.json file

use:

npm i --force

or

npm i --legacy-peer-deps

to override peer dependency. Answered in

Upvotes: 1

chandana
chandana

Reputation: 1

Downgrade to a lower npm version with, for example,

npm install npm@6

Upvotes: -2

Siwei
Siwei

Reputation: 21597

I met the same problem.

try to run the command with --force , if you don't use the related package.

e.g.

npm install --verbose --force

Upvotes: 2

Trott
Trott

Reputation: 70183

npm@7 has stricter dependency resolution than previous versions. If you can update the version of webpack in your root project, that may resolve it. An alternative easy quick thing to try is npm install --legacy-peer-deps.

Upvotes: 17

Related Questions