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

Does yarn installs peer dependencies? #8551

Closed
padzikm opened this issue Jan 17, 2021 · 3 comments
Closed

Does yarn installs peer dependencies? #8551

padzikm opened this issue Jan 17, 2021 · 3 comments
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.

Comments

@padzikm
Copy link

padzikm commented Jan 17, 2021

I have two projects, first one references react and react-dom 16.* and second one references react and react-dom 17.*. react-dom has peer dependency to react. Both projects are inside workspace root folder. After executing yarn install from workspace root there is following structure;

first /
node_modules /
empty
second /
node_modules /
react 17.*
node_modules /
react 16.*
react-dom /
node_modules /
react 17.*

As a result when referencing react-dom it loads its own local version of react, which results in hard to error. On yarn's website there is mention that yarn installs all dependencies, but according to for example issue #1503 yarn does not install peer dependencies. I'm using yarn 1.22.10 - please explain how peer dependecies are handled in yarn?

@merceyz
Copy link
Member

merceyz commented Jan 17, 2021

Yarn doesn't install peer dependencies for you, you need to install those yourself. Your "filetree" doesn't make much sense, please use something like https://tree.nathanfriend.io/ to create one that does.

I'm assuming you have two workspaces both depending on different versions of react but depending on each other, that wont work unless you're using Yarn PnP as node_modules can't represent that on disk

@merceyz merceyz closed this as completed Jan 17, 2021
@padzikm
Copy link
Author

padzikm commented Jan 17, 2021

Here is reproducible repo https://github.com/padzikm/yarn-test - main node_modules includes react-dom, which has its own version of react in its node_modules, despite having react as peer dependency. According to @merceyz answer yarn should not install peer dependency, so there shouldn't be react in react-dom's node_modules. Why it is?

@merceyz
Copy link
Member

merceyz commented Jan 17, 2021

Can reproduce with Yarn 1 so it looks like a bug, however I can't reproduce with Yarn v2 so this seems to be fixed

https://yarnpkg.com/getting-started/migration

@merceyz merceyz added the fixed-in-modern This issue has been fixed / implemented in Yarn 2+. label Jan 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.
Projects
None yet
Development

No branches or pull requests

2 participants