Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] ERESOLVE unable to resolve dependency tree with conflicting deep peerDependencies #2823

Closed
10hendersonm opened this issue Mar 4, 2021 · 4 comments
Assignees
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@10hendersonm
Copy link

Current Behavior:

Installing a module with a peerDependencies that conflicts with one of its dependencies' peerDependencies fails. For example, @wojtekmaj/enzyme-adapter-react-17 has a peerDependencies on React 17. It also depends on enzyme-adapter-utils, which has a peerDependencies on React of 0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0 (not 17). Attempting to install this module causes an ERESOLVE unable to resolve dependency tree error.

 ~/development/projects/tmp/peerdeps-test  npm i @wojtekmaj/enzyme-adapter-react-17
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: [email protected]
npm WARN node_modules/react
npm WARN   peer react@"^17.0.0-0" from @wojtekmaj/[email protected]
npm WARN   node_modules/@wojtekmaj/enzyme-adapter-react-17
npm WARN     @wojtekmaj/enzyme-adapter-react-17@"*" from the root project
npm WARN   1 more (react-dom)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer react@"0.13.x || 0.14.x || ^15.0.0-0 || ^16.0.0-0" from [email protected]
npm WARN node_modules/enzyme-adapter-utils
npm WARN   enzyme-adapter-utils@"^1.14.0" from @wojtekmaj/[email protected]
npm WARN   node_modules/@wojtekmaj/enzyme-adapter-react-17
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR!   peer react@"^17.0.0-0" from @wojtekmaj/[email protected]
npm ERR!   node_modules/@wojtekmaj/enzyme-adapter-react-17
npm ERR!     @wojtekmaj/enzyme-adapter-react-17@"*" from the root project
npm ERR!   peer react@"17.0.1" from [email protected]
npm ERR!   node_modules/react-dom
npm ERR!     peer react-dom@"^17.0.0-0" from @wojtekmaj/[email protected]
npm ERR!     node_modules/@wojtekmaj/enzyme-adapter-react-17
npm ERR!       @wojtekmaj/enzyme-adapter-react-17@"*" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^0.14 || ^15.0.0 || ^16.0.0-alpha" from [email protected]
npm ERR! node_modules/enzyme-adapter-utils/node_modules/airbnb-prop-types
npm ERR!   airbnb-prop-types@"^2.16.0" from [email protected]
npm ERR!   node_modules/enzyme-adapter-utils
npm ERR!     enzyme-adapter-utils@"^1.14.0" from @wojtekmaj/[email protected]
npm ERR!     node_modules/@wojtekmaj/enzyme-adapter-react-17
npm ERR!       @wojtekmaj/enzyme-adapter-react-17@"*" from the root project
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 /Users/me/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/me/.npm/_logs/2021-03-04T18_02_11_999Z-debug.log

Unfortunately, I control neither of these packages, and have zero power to update them. This can be bypassed with --legacy-peer-deps, but I distribute an app starter to my user base and I'd like to avoid leaving purposefully legacy things in the generated .npmrcs come October when this all goes LTS.

This isn't isolated to this one instance, I was able to create a minimal reproduction:
https://github.com/10hendersonm/npm-7-peerdeps-repro

Expected Behavior:

Installation succeeds, either with peerDependency warnings OR by placing the conflicting peerDependencies into the node_modules/requesting-module/node_modules/ directory.

Steps To Reproduce:

Minimal Reproduction

Steps in README: https://github.com/10hendersonm/npm-7-peerdeps-repro

TL;DR Create a package with "peerDependencies": { "left-pad": "1.2.*" } and npm pack it. Create a second package with "peerDependencies": { "left-pad": "1.3.*" }, and npm i ../your/packed/tarball.

Real-World Example

npm -v # 7.6.0
mkdir peerdeps-test
cd peerdeps-test
npm init -y
# Fails
npm i @wojtekmaj/enzyme-adapter-react-17

image

Environment:

  • OS: ProductName: Mac OS X, ProductVersion: 10.15.7, BuildVersion: 19H114
  • Node: 14.15.0
  • npm: 7.6.0
@10hendersonm 10hendersonm added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Mar 4, 2021
@ljharb
Copy link
Contributor

ljharb commented Mar 4, 2021

This is by design. enzyme does not support react 17, and thus neither does enzyme-adapter-utils, so it's simply not possible to have a valid dependency graph that has both enzyme and react 17 in it.

That adapter fork isn't fully compatible with React 17 (or else it'd be part of enzyme already), so you're taking a risk by using it - but either way, for it to truly bypass the peer dep restrictions, it'd have to fork enzyme-adapter-utils as well.

The proper solution is to stick with React 16 until enzyme is able to properly support React 17.

@10hendersonm
Copy link
Author

I guess I'm pretty shaky on the internals of npm tree-building, but something like this wouldn't be possible?

- node_modules
  - react@17
  - @wojtekmaj/enzyme-adapter-react-17
      - node_modules
        - react@16
        - enzyme-adapter-utils

@ljharb
Copy link
Contributor

ljharb commented Mar 4, 2021

Technically yes - but because the adapter fork declares it as a peer dep, not a regular dep, i'm not sure how that could be done by npm automatically.

Additionally, then you'd have two copies of React, which breaks React itself, so that's not a viable solution anyways.

@darcyclarke
Copy link
Contributor

@10hendersonm can you try replicating this problem on the latest version of npm? (ie. npm i -g npm) We've made improvements to peer dependency resolution over the last number of releases which may help here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

3 participants