Hard to transition to workspaces working with other repos because of peerDependencies
Closed this issue ยท 2 comments
I've done a repo that explains the problem, the solutions we've been thinking about and steps to reproduce with the files.
Yarn workspaces peerDependencies resolution repo
The issue summary
We want to be able to dev on a package "package-a" belonging to a yarn workspace while it is linked in a project "project-a" not related to this workspace.
We want to always have the same results than in prod, like when packages are taken from the registry for instance.
- package-a belongs to the workspace and has a peerDependency on log-version ^1.0.0
- package-b and package-c belongs to the workspace and both have a dependency on log-version@1.0.0
This makes log-version@1.0.0 be hoisted by the workspace
- project-a has a dependency on log-version@1.1.0 and on package-a (version doesn't matter)
workspaces
|-- node_modules
|-- log-version@1.0.0
|-- packages
|-- package-a (peerDependency: log-version ^1.0.0)
|-- package-b (dependency: log-version@1.0.0)
|-- package-c (dependency: log-version@1.0.0)
project-a
|-- node_modules
|-- log-version@1.1.0
|-- package-a
package.json
* dependency:
- log-version@1.1.0
- package-a
In dev
We link package-a in project-a and run project-a:
- project-a has log-version@1.1.0 in dependency so uses version 1.1.0 when running
Expected behavior
- package-a has log-version ^1.0.0 in peerDependency so running in project-a, should use log-version@1.1.0
Current behavior
BUT, package-a in fact uses log-version@1.0.0 because it is found in the workspaces root node_modules before!
Follow the steps, having in mind that package-a is linked into project-a:
workspaces
|-- node_modules // STEP 3
|-- log-version@1.0.0 // STEP 4
|-- packages
|-- package-a (peerDependency: log-version ^1.0.0) // STEP 2
|-- package-b (dependency: log-version@1.0.0)
|-- package-c (dependency: log-version@1.0.0)
project-a
|-- node_modules
|-- log-version@1.1.0
|-- package-a // STEP 1
package.json
* dependency:
- log-version@1.1.0
- package-a
In production
- project-a has log-version@1.1.0 in dependency so uses version 1.1.0 when running
- package-a has log-version ^1.0.0 in peerDependency so running in project-a, uses log-version@1.1.0
When not linked, we do have:
project-a
|-- node_modules
|-- log-version@1.1.0 // STEP 2
|-- package-a // STEP 1
package.json
* dependency:
- log-version@1.1.0
- package-a
Note : The readme in the repo is much more detailed, I didn't know if I should have gone to this level of detail in the issue description. I can edit this post and add everything if you prefer ๐
Environment
- nodejs@8.12.0
- yarn@1.12.3
- OS: Tried on MacOS and Ubuntu 18.04
Anyone ? ๐
I'm closing since @arcanis said this had to be done with Yarn PnP ๐