I'm using a library that has supports another library with a wide range of versions as a peer dependency. Unfortunately, one of the child projects of the workspace pulls in a version different from the child project that uses the library. As a result, they end up requiring different versions.
I'm trying to use selective resolutions to handle this and force it to use the correct version (https://yarnpkg.com/lang/en/docs/selective-version-resolutions/) but I'm not having any luck.
It's possible I'm misunderstanding how to utilize these.
My current setup is I have a root workspace with these children inside: Project A package.json (which is the source of the issue):
dependencies: {
backbone.marionette: '2.4.1'
}
Project B package.json (which is the application having issues):
dependencies: {
backbone.marionette: '1.8.8',
@organization/UILibrary: '0.0.22'
}
The @organization/UILibrary (which is outside the workspace) package.json looks like so:
peerDependencies: {
backbone.marionette: ">= 1 < 3"
}
Unfortunately, even though Project B has no dependency on Project A, when @organization/UILibrary is pulled into Project B it gets backbone.marionette version 2.4.1 for it's requires (whereas the requires local to Project B get 1.8.8).
My attempt to use resolutions is updating Project B package.json to this:
dependencies: {
backbone.marionette: '1.8.8',
@organization/UILibrary: '0.0.22'
},
{
"resolutions": {
"@organization/**/backbone.marionette": "1.8.8",
"@organization/backbone.marionette": "1.8.8",
"@organization/UILibrary/backbone.marionette: "1.8.8",
"@organization/UILibrary/**/backbone.marionette: '1.8.8"
}
Any ideas? Based on some digging in yarn's issues and some of their selective dependency PRs (see https://github.com/yarnpkg/yarn/issues/4874) I believe it may be due to the fact that the UILibrary is scoped (has a slash).
I ran into something similar recently; what I found is that resolutions
only works in the root package.json
. Try moving the resolutions
there instead of in Package B's.