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

Peer Dependency installed incorrectly #1661

Closed
kostasmanionis opened this issue Nov 3, 2016 · 5 comments
Closed

Peer Dependency installed incorrectly #1661

kostasmanionis opened this issue Nov 3, 2016 · 5 comments

Comments

@kostasmanionis
Copy link

Probably a bug.

I have a project that depends on "react": "^15.3.0" & "react-relay": "^0.9.2"

React-relay states it's peer dependencies like this "react": "^15.0.0 || ^0.14.0"

Now when installing with yarn, for some reason, react-relay get's a separate version of react.

I end up with this

node_modules/react@15.3.2
node_modules/react-relay/node_modules/react react@15.1.0

Shouldn't react-relay be using react@15.3.2?

Maybe some other package could be causing this, any ideas?

Running on
Yarn 0.16.1
OSX 10.11.6
Node v6.9.1

@twhid
Copy link

twhid commented Nov 3, 2016

FWIW, this was fixed by moving react from "dependencies" to "peerDependencies" and "devDependencies" in direct dependencies of the project in question. React was erroneously included as a dependency in some internal libraries of ours, when it should have been a peer and dev dependency.

However, it should be noted that npm@3 was able to install dependencies in a way where the direct react dependency satisfied react-relay's peer dependency on react.

@kostasmanionis
Copy link
Author

Some additional info

yarn why react revealed this

info Reasons this module exists
   - "admin-middleware#admin-layout#vg" depends on it

Package "vg" had react both in devDependencies and peerDependencies

"react": "^15.0.2",

Package "admin-layout" had react and react-relay dependencies.

"react": "~15.1.0",
"react-relay": "~0.9.0",

Package admin-middleware had no react or relay deps.

@exogen
Copy link

exogen commented May 26, 2017

I've been experiencing a strange issue off and on with graphql and graphql-relay, and it's been giving me trouble for weeks. I just tracked it down to this (or a similar) Yarn issue – the issue goes away when I install with npm instead of Yarn.

  • My project depends on graphql and graphql-relay (and they both definitely need to be in dependencies, not devDependencies nor peerDependencies).
  • graphql-relay has a peerDependency on graphql, and it's common for its graphql peerDep to be somewhat behind the latest graphql release.
  • So sometimes, if something else in the tree also depends on graphql, Yarn will cause graphql-relay to get a nested graphql under its node_modules. THIS SHOULD NEVER HAPPEN. peerDependencies should never be "realized" in this way. Even if the graphql version living above/next to graphql-relay is an incompatible version, the most that should happen is a warning. peerDependencies should never be actually installed in the package that declares them. The important part of the "peer" in "peerDependencies" isn't just the version you get, it's the instance.
  • As expected, in this case, it causes an error, because my project and graphql-relay end up with different graphql instances. It's not that they're incompatible versions of graphql (although they might be) – it's that they are different instances when imported, so their instanceof, strict equality, etc. checks are all thrown off.

@ds300
Copy link

ds300 commented Jun 15, 2017

I'm getting this same issue with yarn@0.24.5

there is a repro over here: https://github.com/ds300/styled-components-native-warning-example

in this case styled-components gets a nested version of react@15 despite the fact that react is just a peer dependency for styled-components and the project has react@16 as a direct dependency.

@BYK
Copy link
Member

BYK commented Sep 15, 2017

@ds300 - I tried reproducing this with your instructions and it seems to be getting fixed with #4478 or an earlier PR.

That said it still prints the following warning, which seems legit:

warning "styled-components@2.1.0" has incorrect peer dependency "react@^0.14.0 || ^15.0.0-0".

I'm going to go ahead and close this but feel free to reopen if you think something is still not right.

@BYK BYK closed this as completed Sep 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants