New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pnpm@9.0.4 links incorrect peer dependency when multiple versions of the peer dependency exist in a monorepo #7976
Comments
A peer dependency range is only a suggestion. The most important thing about a peer dependency is that it should be a singleton. If there is a version of the package already installed in the workspace, pnpm will use it instead of installing something new. It is really easy to fix it, just install the version of the peer that you want as a direct dependency. |
Thanks for the super quick reply @zkochan!
Is this defined anywhere? I don't see any such notes in pnpm docs nor in how npm treats peerDeps — https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies Also, in large monorepos, this is effectively impossible as some teams can choose to stay on certain versions of the dependency while other teams are free to upgrade. The e.g., here we have the build tool rollup wherein some teams depend on and use rollup@5 via 3rd party packages in the monorepo while some use rollup@4. An upgrade by one team should not break another teams code in such a scenario. And this btw works as expected in pnpm@8.
What's weird is that even when pnpm@9 sees both versions of a peerDep, it chooses the latest one and seems to disregard whatever peerDep suggestion was provided by the package. This again worked as expected with pnpm@8. Given that aligning versions of the peerDep is not currently possible in this large monorepo I speak of, what other alternatives do I have? |
In that scenario you would need to install a different version of the peer dependency as a direct dependency for the subset of projects that use a different version of the peer dependency. Regardless of this issue, you would need to manually set a peer dependency for one of the groups. |
Thank you for the workaround @zkochan! |
Verify latest release
pnpm version
v9.0.4
Which area(s) of pnpm are affected? (leave empty if unsure)
Dependencies resolver
Link to the code that reproduces this issue or a replay of the bug
https://github.com/zeusdeux/pnpm9-peer-dep-resolution-bug
Reproduction steps
pnpm install
in the workspace root.pnpm why -r rollup
. It will report —cat packages/package-b/node_modules/rollup-plugin-visualizer/package.json | grep -A3 peerDependencies\"
. It will report —Thus we can see that even though in
package-b
,rollup-plugin-visualizer
has a peerDep onrollup
v2 or v3, pnpm links it with rollup v4 which is installed bypackages/package-a
in the repo.Describe the Bug
pnpm
v9 doesn't seem to respect the peer dependency version as made explicit by some package if there are multiple versions of that peer dependency already in the monorepo.Expected Behavior
pnpm
v9 should use the correct version of the peer dependency as specified by any package.Which Node.js version are you using?
20.12.2
Which operating systems have you used?
If your OS is a Linux based, which one it is? (Include the version if relevant)
No response
The text was updated successfully, but these errors were encountered: