berry: [Bug?]: Incorrect linking result (unable to resolve peer dependency)

Self-service

  • I’d be willing to implement a fix

Describe the bug

Consider we have 3 workspaces in a project: service which depends on app which depends on lib. Yarn is configured to use node-modules linker. hoistingLimits for the service workspace is set to workspaces value. Also workspaces app and lib have “react” peer dependency and service depends on “react”.

After installation I expect to have node_modules structure capable to resolve “react” from all of the three workspaces. But in reality lib becomes unavailable to do this.

Below you can see expected and actual resulting structure.

Actual file tree

project
├── node_modules
│   ├── symlink to app
│   └── symlink to lib
├── service
│   └── node_modules
│       ├── symlink to app
│       └── react
├── app
└── lib
Expected file tree

project
├── node_modules
│   ├── symlink to app
│   └── symlink to lib
├── service
│   └── node_modules
│       ├── symlink to app
│       └── react
├── app
│   └── node_modules
│       └── symlink to lib
└── lib

To reproduce

https://github.com/schusovskoy/yarn-peer-repro

Environment

System:
    OS: macOS 12.2.1
    CPU: (8) x64 Apple M1 Pro
Binaries:
    Node: 16.13.2 - /private/var/folders/td/01fyjv6d46x7gtvcn3dq78m40000gn/T/xfs-4662e098/node
    Yarn: 3.2.0 - /private/var/folders/td/01fyjv6d46x7gtvcn3dq78m40000gn/T/xfs-4662e098/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 23 (12 by maintainers)

Most upvoted comments

What about this proposal? It would easily fix --preserve-symlinks scenario and shouldn’t brake any current working code.

Well, you can try, I personally do not believe that this will fix --preserve-symlinks, maybe only this one case that you use, but what about other cases? Try and if E2E and integration tests will not fail, I will look at your code. Plus you need to add an integration test for the case that your code will fix.

Thanks! Now I understand the problem better than before. I’ll go figure it out and try