21

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).

tk421
  • 5,775
  • 6
  • 23
  • 34
Andrew
  • 255
  • 1
  • 2
  • 7

1 Answers1

61

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.

Greg Ferreri
  • 2,652
  • 5
  • 28
  • 38
  • 3
    How do you then scope it to just limit the resolutions for Package B then? Is there a way with globs? – light24bulbs May 26 '21 at 04:24
  • 2
    @light24bulbs yes, how to limit resolutions for specific packages is detailed here: https://classic.yarnpkg.com/en/docs/selective-version-resolutions/#toc-how-to-use-it – Hooray Im Helping Dec 07 '21 at 23:59
  • 2
    except not so detailed. the format of that "path" is not clear. Is it the package name? or folder structure? What about scoped names? Yarn seems to decide that it doesn't like my attempts and so it deletes them from my package.json itself without any explanation. – Jason Kleban Jul 20 '22 at 03:19
  • But how does one specify the workspace? None of the syntax versions i've tried work. Only all workspaces or none at the moment. – Ivan P Apr 14 '23 at 03:14
  • Any update on this? Yarn 3 is not supporting patterns – Andrii Tsarenko Jul 12 '23 at 11:31