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

[Feature] Add option to yarn install to avoid hoisting deep dependencies #4423

Closed
2 tasks
HiiiiD opened this issue May 2, 2022 · 4 comments
Closed
2 tasks
Labels
enhancement New feature or request

Comments

@HiiiiD
Copy link

HiiiiD commented May 2, 2022

  • I'd be willing to implement this feature (contributing guide)
  • This feature is important to have in this repository; a contrib plugin wouldn't do

Describe the user story

Today I've encountered an issue when moving from NPM to Yarn with a project. Yarn tries to hoist deep dependencies and doing so breaks some build actions that depend on these packages.
I'll show a brief example:

  • svelte-material-ui@4.2.0 have @smui/textfield@4.2.0 as direct dependency
  • @smui-extra/autocomplete@6.0.0-beta.16 have @smui/textfield@6.0.0-beta.16 as direct dependency too

Now, when performing yarn install, @smui/textfield on the root of node_modules is at version 6.0.0-beta.16 but I want it to be at version 4.2.0. @smui-extra/autocomplete dependencies should be completely isolated from the rest of the root dependencies in order to not interfere with them.

Describe the solution you'd like

I'd like to have an option when performing a yarn add that allows to avoid hoisting deep dependencies, in order to share multiple package versions for multiple direct dependencies.

Describe the drawbacks of your solution

There's one drawback to my solution, that is the increased bundle size of the node_modules folder due to duplication of dependencies.

Describe alternatives you've considered

I've researched alternatives for over a day but found none. Also, I think that this issue can be related to this feature request

@HiiiiD HiiiiD added the enhancement New feature or request label May 2, 2022
@merceyz
Copy link
Member

merceyz commented May 2, 2022

Have you had a look at https://yarnpkg.com/configuration/yarnrc#nmHoistingLimits?

@HiiiiD
Copy link
Author

HiiiiD commented May 2, 2022

Of course but it is a "global" functionality, I'd like to have the same functionality for a single dependency.

@larixer
Copy link
Member

larixer commented May 2, 2022

If the package needs a specific hoisting layout it means there is a bug either in this package or in the packages that use it. The best course of action here is to fix the bug in the relevant packages and not to try to cure symptoms.

Also, I think that yarnpkg/yarn#5705 can be related to this feature request

This issue is not related, because Yarn 3+ (and high versions of Yarn 2+ too, I just don't remember a specific version when this was implemented) gives priority to direct workspace dependencies during hoisting, so deep dependencies cannot shadow direct workspace dependencies in the case of Yarn 3+.

@smui/textfield on the root of node_modules is at version 6.0.0-beta.16 but I want it to be at version 4.2.0

You can achieve this by adding dependency on version 4.2.0 of @smui/textfield to your root package.json, Yarn will have no choice but to use exactly this version in the root node_modules

@HiiiiD
Copy link
Author

HiiiiD commented May 2, 2022

@larixer thanks so much for your support, I'll try to do what you said.

@HiiiiD HiiiiD closed this as completed May 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants