-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Error: No QueryClient set, use QueryClientProvider to set one (vite, react-query, pnpm) #3707
Comments
This usually means that you have somehow pulled in two versions of react-query, or two versions of react. React Query merely creates a new context provider and reads from it. If you have two versions, they will have different contexts, so the read won't work and we'll throw that error. Make sure your package / module has defined react-query as |
Thanks for the quick reply.
Is there any way for me to find out if this is the case ? PS: I don't think this is the issue here, as pnpm should make sure I only use a single version of those packages across the entire workspace
I tried to do this in the Thanks |
okay, we have had issues with here is a similar issue where the problem was wrong dependency resolution: this (open) issue also looks similar, but I haven't gotten any updates there: and this discussion about microfrontends was also about wrong versions of RQ: |
PS: I quickly checked
both of which appear to point to the exact same versions ... but AFAIK pnpm provides those by creating symlinks/hardlinks of the files in the local node_modules folders to a central package cache directory. I can't speak for if this is causing such trouble as you describe when the final JS production bundle is built ?! |
can you check the final bundle if you see any indication of react-query being in there twice? For example, the string |
I only find one occurrence of edit: #3595 does indeed sound like it might be the same (or at least a similar) problem |
then let's continue the discussion in #3595 please |
Make sure your library has all peer dependencies listed in your rollup config in your vite config file: build.rollupOptions.external |
For anyone else having this problem when using Vite. You need to add @tanstack/react-query to the vite.config.ts rollupOptions
|
thanks @donalnofrixion, it works! |
@donalnofrixion how about in NextJs, getting same issue |
Describe the bug
I am using pnpm workspaces to manage my mono-repo.
In the repo I have a vite-app and several other private packages/modules that the app depends on
When running the vite-app...
pnpm dev
(the hot-reload / watch mode) ... the REST queries performed via react-query work finepnpm build
+pnpm preview
(production bundling + static http server) ... the REST queries fail and the browser console shows the error:Your minimal, reproducible example
https://github.com/drywolf/react-query-error-No-QueryClient
Steps to reproduce
see
README.md
in the linked repository (https://github.com/drywolf/react-query-error-No-QueryClient)(also I tried to make each step a separate git commit)
Expected behavior
The react-query REST requests should work regardless if it is in the vite hot-reload server or a production build bundle.
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
Windows 10 Pro 21H1
Build 19043.1706
react-query version
v3.39.1
TypeScript version
v4.7.3
Additional context
The error only seems to happen if the react-query hook is called from within a function of a package/module that is linked via pnpm-workspace to the vite-app.
If I put the same hook function+query into a .ts file directly at the vite-app, then the error does not happen.
Maybe related to #3505 ?!
The text was updated successfully, but these errors were encountered: