-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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.overrides doesn't override peerDependencies #6759
Comments
Similar in nature to: #4097 |
Why don't you just install react v18.1.0 as a dev dependency of your project? In that case it will resolve the peer dependency. |
This stumped me for a while. I knew that I needed to override the peer dependency, so reached for the overrides feature, but it did not work. Maybe from a usability point of view, the overrides feature should also override peer dependencies, even though it can technically be solved by installing the dependency directly. |
💯, it is indeed easy to fix it that way in this example. But the real-life issue I hit was unrelate to So let's say I have my modules
Due the way TS compilation works with global namespaces and what not, importing stuff from I was able to create a small reproduction here: https://github.com/stefanmaric/pnpm-overrides This is similarly the issue I'm presenting in the project that spawned this issue: ![]() "Fixes" itself if I don't import from ![]() Of course in this case it is easy to simply install all the peer-dependencies across all packages, but at work I have a monorepo with 20+ packages and it was almost impossible for me to find the offending packages; I actually had to spend about 2h today fiddling around and inspecting the node_modules/ tree to try the explicit declaration of peerDependencies workaround., this is on top of the knowledge I had already from working around it with hooks. Agree this is an weird edge-case due to TS's weirdness, but nonetheless, I would expect |
ok, I have no objections
You can just install it in the workspace root. |
I think it's worth mentioning on the usability side of things, that with implicit peer dependency installations, most users won't actually be able to tell if it's a transitive dependency, or a peer dependency which is causing the problems. In my case, I had a package which depended on an old version of However, it was very difficult to workout which package was actually including Ultimately, I knew I needed to override the version, but thought for many hours that it was an ordinary transitive dependency, in which case |
They were actually installed in the workspace root to begging with, |
To clarify, this issue popped up while upgrading pnpm from v7 to v8. The peerDependencies situation in this project has been messed up for a long time but it manifested itself with v8 because of of the automatic installation of peerDependencies, precisely because of nodejs' module resolution: In v7 the nested module |
pnpm version: v8.6.6
Code to reproduce the issue:
Init a new pnpm package:
Add react-dom:
Check the installed dependencies:
You should see something like this:
react@18.2.0
was installed because it is apeerDependency
fromreact-dom@18.2.0
andauto-install-peers
istrue
by default in pnpm v8.Now pin the
react
dependency to an older version usingpnpm.overrides
insidepackage.json
:Remove lockfile and node_modules for good measure:
Install again:
Expected behavior:
I would expect the installed
react
version to follow the override and be18.1.0
.For example:
Actual behavior:
Version
18.2.0
ofreact
is still installed:Additional information:
node -v
prints: v20.3.1To workaround this issue, I get the desired behaviour using the following pnpm hook:
The text was updated successfully, but these errors were encountered: