Skip to content

Problem with peer dependencies when using pnpm link #6804

@kevinpastor

Description

@kevinpastor

When a package that has peer dependencies is linked to some destination, the node_modules of that package are included in the symbolic link. This causes the dependencies of the package to come from another source than the destination's node_modules/.pnpm folder. This becomes a problem with peer dependencies, because they end up not pointing to the same exact file. Even when the version on both side is an exact match, this can lead to problems when exact references (e.g.: singleton) are needed.

The simple example is for a React package, where React is marked as a peer dependency. When a consumer package links the first library, there will be a missing in the imported files, leading to countless problem on runtime.

pnpm version:

8.6.3

Code to reproduce the issue:

I've created a reproduction repository that includes a README.md file with all the instructions needed in order to get a better feel of the issue.

https://github.com/kevinpastor/pnpm-link-peers-issue

Expected behavior:

When linking a package that has peer dependencies to some destination, we should expect that the peer dependencies are respected.

Actual behavior:

The peer dependencies of the package behave more like dependencies. The peer dependencies are consumed from the package's original location and not from the destination's node_modules.

Additional information:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions