Building with Turbo/PNPM/Vite and Orval results in double context
Hi
Our dev build works fine, but our production build seems to end up with double react-query context definitions (I can confirm this looking at the resulting bundle), causing our app to fail with the infamous "No queryClient provided etc".
We have an application inside our repo at
apps/web-next and our Orval API get's generated at packages/bff-api. react-query is setup as a peer dependency inside bff-api but it is important to note: we do not actually build this bff-api package separately. It is basically just source code and our Vite build inside apps/web-next picks it up as such.
I've read through pretty much all github / discord issues I was able to find about the topic, tried all of the suggestions but to no avail.
I expect it has something todo with the way rollup is bundling, rather than react-query itself.2 Replies
metropolitan-bronze•3y ago
did you see this?
https://github.com/pnpm/pnpm/issues/5351
was fixed with v8 of pnpm (opt-into v7 with a flag)
GitHub
pnpm creates multiple installations for same dependency · Issue #53...
pnpm version: 7.11.0 Code to reproduce the issue: I have a workspace with main app A and a library B. A had react-query as a dependency. B has react-query as a peerDependency. For library B to be a...
afraid-scarletOP•3y ago
Yes, but I don’t have multiple installs of react-query in my pnpm lockfile.
After some more debugging I found my packages/bff-api orval folder contained a node_modules folder with react-query, while my apps/web-next folder was using the hoisted package (which resides in our repo root)
When I removed the node_modules folder and ran pnpm install again it did not contain react-query anymore and it also used the hoisted package at root, solving our problem.
We have node-linked=hoisted enabled inside our .npmrc, but I suppose a package local to the folder always wins out on the hoisted one causing this behavior
As to how the react-query ended up inside the node_modules folder of our bff package, I am a bit unsure. Might be from before it was listed as a peerDep (used to be a regular dep) in the package.json
I am also on native Windows, which has caused pnpm linking issues before, so maybe that had something todo with it as well. 🤷♂️
@TkDodo 🔮 thanks for your input tho!