-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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]: Yarn does not dedupe in-range compatible versions of dependency in child workspace #5948
Comments
… when in the lume repo and using yarn for bootstrap. yarnpkg/berry#5948
* main: try yarn resolutions to fix wrong version of solid-js being installed when in the lume repo and using yarn for bootstrap. yarnpkg/berry#5948 update prettier to 3.0.3 infra: add .gitattributes with rules to enforce that code is checked out with LF line endings only, which prevents Prettier from failing in Windows remove pointer events polyfill (pep.js) forward old docs URLS to docs.lume.io update menu URLs
Yarn does not dedupe implicitly, because that could update transitive deps and break things. Instead, dedupe must be done explicitly with the A fundamental design choice of Yarn is that within the same project (i.e. across all workspaces and transitive dependencies), the same descriptor (e.g.
If you are fine with downgrading all instances of This is also why your feature request is kinda clunky. A resolution in a workspace
|
I understand the premise and appreciate its value, but I think there might still be a bug (or missing feature) here because:
With these data points, there does not seem to be a reason to avoid deduping packages within I'm not aware of how yarn.lock works, but maybe it needs to be able to hold a little more information to allow workspaces that are essentially-standalone projects to be deduped on their own automatically. I think this is very expected by anyone who will encounter this, and people in such cases won't be able to intuitively reason as to why in-range versions are not deduped apart from "Yarn just doesn't dedupe". I.e. there's no real intuitive reason why the packages need to be duped and why manual deduping has to be performed. Without deduping whenever possible, there's also the risk that projects that depend on singletons (front-end reactive projects, reactive state libs, etc) will simply break, which causes the requirement for manual intervention seem even less of a good out-of-the-box behavior. I reported this as "bug" because its fairly standard behavior for I've verified that npm run fresh with rm -rf packages/docsifyjs+docsify yarn.lock && npm i With Yarn, even if I first delete Over in various people are stumbling on npm's lack of hoisting control now that Lerna 7+ no longer installs and links workspaces and instead directs people to use npm, yarn, or pnpm for that purpose. Those people that are starting to trickle over from Lerna may hit this issue next. Should this be converted into an enhancement ticket? |
No, this is a core behavior of Yarn that's not going to change as a default. New installs are additive, not destructive. Running If you wish to dedupe your project you can run Additionally, note that dedupe may come in multiple strategies, some more destructive than others, so we definitely want the users to be explicit about what level of risk they can tolerate. |
You understand
If we accept that the "same resolution" constraint is valuable and should not be changed, then
If a package depends on singleton packages, it should declare peerDependencies instead of dependencies. The semantics of npm can also duplicate packages, but it is much less predictable when and how it happens. Simply upgrading a direct dependency of your project can cause previously deduplicated packages anywhere in the dependency tree to duplicate. Deduping whenever possible will also break some projects because adding a direct dependency can also upgrade or downgrade packages anywhere in the dependency tree. The takeaway is that, if packages do not properly declare their dependencies, then deduping implicitly and deduping only explicitly both causes problems. But deduping only explicitly is less problematic because you know what and how it is happening.
Not saying it is npm's fault -- if everyone follows semver, properly declares their dependencies, and not rely on deduplicated packages when they were never guaranteed, etc. then those problems should not happen even in npm. Yarn just values stability and predictability more than npm within the confines of the semantic guarantees. By your logic, not having hoisting controls is also a standard behavior of
The semantic guarantees are like I said above -- that |
I get it. You're saying it works the way it works. I'm just saying just because it worked that way for 7 years doesn't make it the best way. I want to rely on semver versioning benefits, and yarn prevents that out of the box (but now I know, so I have to make sure I run dedupe manually to avoid surprises). |
I think there's definitely a bug. There's absolutely no reason for Reproduction:
The output still shows non-deduped This should be deduping because:
Even with
This is what I described above, but now I've described it in a different way. I'm fairly sure this is a bug (unless there's something inside of |
Which resolves to https://github.com/lume/lume/blob/develop/yarn.lock#L24771-L24772 As mentioned in the
By default Ideally we would have a |
Self-service
Describe the bug
I have multiple packages that depend on
solid-js
in a child workspace. After yarn install at the top of the root, I see the following inside a child workspace:The child workspace has
"solid-js": "1.4.x"
in package.json, while the dependencies that depend on solid-js have"solid-js": "^1.0.0"
in their package.json files, which means that all three version ranges for solid-js are intersecting.Because the ranges intersect, I expect there to be a single version of
solid-js
insidenode_modules
of the child workspace.Here are the versions I see get installed:
Because of this issue, I tried to see if there's a way I can fix it using
resolutions
, with no luck.I tried putting this in the child workspace:
as well as
but either way the end result is the same and the issue is not fixed.
To reproduce
For reference, here's that commit in GitHub UI: https://github.com/lume/lume/tree/11f5894239959d021046fe158a92284559c1d7cb
Then run this to set up git submodules and bootstrap with yarn:
Finally observe the installed solid-js versions:
I used the
find
command because neitheryarn ls solid-js
ornpm ls solid-js
show the installed versions ofsolid-js
.See
apps/website/package.json
, which has theresolutions
field in it (even ifresolutions
worked it shouldn't be needed)Environment
Additional context
The text was updated successfully, but these errors were encountered: