No QueryClient set, use QueryClientProvider to set one (yarn workspaces)
Hello,
I've a monorepo build with yarn workspaces, I've a components workspace that contains all my shareables components and another workspace that contain the APP.
I've install the react-query library as a dependency in the app workspace and set it up as peer dependency in the component workspace
Here is the APP component
And how i'm using useQuery inside the component :
What am I doing wrong ?
Thank you
9 Replies
wise-whiteOP•4y ago
Here is my APP packages.json
And here the component workspaces packagae.json
harsh-harlequin•4y ago
Almost always, it's because you somehow have two versions of react-query around.
rare-sapphire•4y ago
@TkDodo 🔮 I have the same problem only my package s do not live in the same repo, they are published on NPM. But since the upgrade to v4 I get the "No QueryClient set" error. I made sure that
@tanstack/react-query is a peerDependency. I've been stuck on this for days now. Any idea ?harsh-harlequin•4y ago
which package manager are you using? I know pnpm has some issues in that regard because I stumbled also:
https://github.com/pnpm/pnpm/issues/5351
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...
rare-sapphire•4y ago
@TkDodo 🔮 I use yarn. I made sure that react and react-dom are also in the peerDependencies list, but nothing helped.
foreign-sapphire•3y ago
We're getting this issue too. We can't upgrade past 4.2.3.
yarn why shows we only have 1 version of React Query and 1 version of react installed.
I wonder if there's some mix of CJS and ESM versions being used or something? Just speculating, not sure I know enoughcorrect-apricot•2y ago
Seems the issue persists in v5 of the library.
I got a similar issue, where I attempted extracting out a simple hook from a host app into a standalone npm package. And the host app as a result would complain
Error: No QueryClient set, use QueryClientProvider to set one. The client is set and wouldn't have such an error when using the host app's local version of the same exact hook.
The hook in question is very simple, quite literally:
The published package defines a peerDependency with the exact same version "@tanstack/react-query": "^5.45.1" found in the host app's yarn.lock (using yarn classic).
Is there any workaround?harsh-harlequin•2y ago
I can assure you there is no issue in the library. You get this error when you have multiple versions of react-query, so the react context that the provider creates is not the same as the react context that the consumer consumes. It's a bundling / installer / setup issue that you would likely also have with any other library that uses react-context
correct-apricot•2y ago
The hook which is packaged doesn't bring its own dependency of
@tanstack/react-query, but designated only as peerDependency. I worked around this issue through designating the exports definition in package.json, which typically isn't required
Granted, this is probably because the involvement of react context as you mentioned. Perhaps a mention in the documentation for such case (covers packaging react-query based hooks as standalone packages, a monorepo/workspace setup, etc), with caveats such as ensuring consistent react-query version, and pay attention to how the esmodules/commonjs exports are handled would be helpful