-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Yarn workspace not hoisting dependencies correctly #7572
Comments
Sorry, bumping this issue to keep it alive. |
I'm seeing both incorrect resolution and hoisting as well with at least v1.17.3, v1.18.0, and v1.19.0.
First off they both should resolve to 9.0.7, because that satisfies Additionally, Yarn's own output of
In reality, 9.0.0 was placed in the root and 9.0.7 was placed in |
Having the same issue with |
Same issue here. Can this issue be assigned for resolution? |
Same issue here as well. |
I have also problem with dependency hoisting. From https://classic.yarnpkg.com/en/docs/workspaces/ I assumed that the hoisting is done only when all of the modules specify the same dependency... In my case I have two workspaces For now, my solution is to forbid hoisting at all. E.g. change "workspaces": {
"packages": [
"A",
"B"
],
"nohoist": [
"**"
]
}, I would say this workaround is a fix for the problem above... Am I misunderstanding something? Or this is intended behaviour? If so, can you explain the reasoning behind this? |
@Siegrift According to the issue it obviously does not matter whether all packages have the dependency or just one or few if external references are taken into account. Using
The bigger problem is then preventing Yarn from installing deps for other packages when you want to build e.g. one package on your CI (this is related #4099) But it would be great if someone one could clarify the hoisting strategy. |
@Fallup Yeah, there are a few specific points that would be nice to address:
With selective approach you never know if you workspace doesn't accidentally pick up unwanted dependency. I will gladly trade off space for this guarantee. And I guess it also resolves #4099, because the workspace has all of it's modules installed inside it's |
@Siegrift Possible issues should be definitely communicated in a clearer, more explicit way. Although they were partially mentioned in Introduction to workspaces - limitations and caveats first point:
I'd also suggest to read Dependencies done right which explains few issues related to hoisting which might partially answer your 2. question. Regarding the selective approach, this is the quote directly from yarn nohoist blog:
Nohoisting everything does not resolve #4099 as "nohoist everything" does not equal to installing "one package in isolation" - it rather install all packages, but with deps. not getting hoisted to the root. Hoisting has always been an issue and if your monorepo is small enough and you can afford it, then nohoisting everything might save you a few headaches. |
I just ran into some strange issues hoisting with the following: structure
package.json "workspaces": {
"nohoist": [
"**/react-native",
"**/react-native/**",
"**/react-native-*",
"**/*-react-native"
],
"packages": [
"apps/*",
"libs/*"
]
}, All three have the same version of
This causes invalid hook errors due to having multiple I was able to get it to work by moving Any thoughts? |
I was in the same situation and went for |
Is it better to only have |
fixed |
Have you managed to find some solution? Dealing with exactly this problem |
I ended up upgrading to yarn berry and the experience with workspaces is much better and more consistent. |
@ianmartorell but does it somehow solve the unpredictable hoisting? |
Yeah, I haven't had more hoisting issues since upgrading. I was previously using nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-berry.cjs
nmHoistingLimits: workspaces Dependencies are properly hoisted to each workspace and the result of |
Closing as fixed in v2 by using either the |
@merceyz should this be closed thought? From the link you've provided:
this repo tracks v1 AFAIK - does it mean there's no chance in fixing this behavior in v1? |
From the release blogpost, from almost a year ago:
Which can be easily validated: Just like what happens when any open-source project releases a new major, all of our resources have been, and will be, spent on the Modern codebase. As we stated before, Classic will remain exactly as it is, and we strongly recommend upgrading when you have the chance (Why?). |
From my experience, Berry with |
I keep running into a version of this with modular
Hilariously, yarn says it is hoisted when it isn't. I get that I can probably solve this with I appreciate that fixed in v2 is significant to the yarn team and to others who can take this plunge, but it's really not feasible for our team to adopt bleeding edge pre-release software for so many tools. Because yarn does not exist in a vacuum. The current JS ecosystem is incredibly demanding and in my context it wastes a lot of frontend time wrestling with these tools instead of focusing on user experience as we should. I wish that this weren't the case. But if wishes were horses, we'd all ride, so I am left with my regret that this "me three" comment isn't likely to help anything. |
Yarn 2.0 got released a year and a half ago. We've had the time to release another major since then. I don't think the "bleeding edge pre-release" moniker is justified 🙂 In any case, hoisting in v1 will certainly not change, especially as it's one of the most complex and prone to break area. There's a reason why we decided it was worth reimplementing it. |
Is it under a different name? Because I checked 3 times and did not see a canonical 2.x release. Only rc pre-releases. If you're not ready to change that, how could I possibly view it as anything other than an unstable pre-release used lightly by early adopters? Certainly I appreciate that input, but there is a reason I perceive it as I originally said. |
Having the same issue with yarn v1.22.5
|
anyone can explain how yarn v3 hoisting works? https://yarnpkg.com/configuration/yarnrc#nmHoistingLimits |
Do you want to request a feature or report a bug?
Possible bug.
What is the current behavior?
Yarn workspace seems to be counting the references from external modules to decide whether to hoist a module or not. This causes an unexpected behavior in my opinion. A minimal reproduction can be looked at this repository.
In the repo, there are 3 packages, called serviceA, serviceB, and serviceC.
react@16.8.6
,react-dom@16.8.6
andreact-image-fallback@8.0.0
react@16.9.0
,react-dom@16.9.0
After running
yarn install
in the project root, we end up withreact@16.8.6
andreact-dom@16.9.0
in the root node_modules. This mismatching version can cause problems in react apps.What is the expected behavior?
I expected that
react@16.8.6
andreact-dom@16.8.6
to be installed in serviceA's node_modules, andreact@16.9.0
,react-dom@16.9.0
to be hoisted to root node_modules because there are more local packages that depends on them.Even when I run
yarn why react
,yarn
itself seems to be expectingreact@16.9.0
to be hoisted, notreact@16.8.6
.Please mention your node.js, yarn and operating system version.
Node version: 10.16.2
Yarn version: 1.17.3
OS version: macOS 10.14.6
The text was updated successfully, but these errors were encountered: