yarn uses wrong version on workspaces

Viewed 214

I have a huge project, which I was will simplify for the issue, with 2 workspaces.

The main packages looks like

  workspaces: [ 'workspace-A', 'workspace-B' ]

My workspace-A has a dependency to external package (here, jest), in a needed version

  name: "workspace-A",
  dependencies: {
    "jest": "<27.0.0"
  }

My workspace-B has a dependency to the same package, but doesn't care about its version.

  name: "workspace-B"
  dependencies: {
    "jest": "*"
  }

After a yarn install (with yarn v3), I was expecting yarn to automatically install jest with a 26.x.x version in my main node_modules. Instead, the node_modules of the main project contains jest 26.x.x, and the node_modules of the workspace-B contains jest 27.x.x. It's OK for my, even if I find this weird, but the thing is the workspace-A now uses jest 27.x.x! I succeeded make it work by adding a resolution field in the main package file, but it's not ideal, as this package doesn't need jest.

  "resolutions": {
    "jest": "^26.6.3",
  }

My 2 questions are

  • Why is yarn installing 2 versions of jest, is there a way to prevent this?
  • Is there a configuration somewhere I should put to specify to the workspace-A to not use something from workspace-B?

Thanks for reading

0 Answers
Related