npm install fails with ERESOLVE dependency conflict even though the peer dependencies seem compatible #206271
🏷️ Discussion TypeQuestion BodyI’m working on a JavaScript/Node.js project and recently started getting an ERESOLVE error when running: npm install The error indicates a dependency conflict involving peer dependencies. However, the versions of the packages I’m using appear to be compatible. For example, npm reports something similar to: npm ERR! code ERESOLVE npm ERR! While resolving: my-project@1.0.0 npm ERR! Could not resolve dependency: I understand that npm performs peer-dependency resolution, but I’m not sure what the recommended approach is in this situation. |
Replies: 1 comment 1 reply
|
The recommended approach is to fix the dependency tree rather than immediately using First, inspect the dependency tree: npm lsFor a specific package: npm ls package-aYou can also inspect why a package is installed with: npm explain package-aIf while your project explicitly requires: then those version ranges are incompatible. npm is correctly reporting that it cannot construct a dependency tree satisfying both requirements. The preferred solutions are:
Similarly: npm install --forceshould not normally be the first solution. It tells npm to proceed despite protections that would otherwise prevent the installation. So the general workflow is: npm ls
npm explain <package-name>Then check the packages' If the conflict is caused by a package you don't control, opening an issue with that package maintainer may be appropriate. If the dependency ranges genuinely cannot overlap, npm's |
The recommended approach is to fix the dependency tree rather than immediately using
--forceor--legacy-peer-deps.First, inspect the dependency tree:
For a specific package:
You can also inspect why a package is installed with:
If
package-brequires:while your project explicitly requires:
then those version ranges are incompatible. npm is correctly reporting that it cannot construct a dependency tree satisfying both requirements.
The preferred solutions are:
package-bto a version that supportspackage-a@2.package-ato a version compatible withpackage-b.package-bif it is no …