T
TanStack4y ago
conscious-sapphire

Error No QueryClient set, use QueryClientProvider to set one

We created a Next.js App and wanted to use the generated function from the backend. To generate the functions we use orval and they are published in a npm repository as we don't use a monorepo. But now we are getting this Error, but we added the QueryClient to the _app.tsx. Here is the example where the error can be reproduced: https://github.com/schoolutilities/react-query-example Has anyone an idea why this error occurs?
GitHub
GitHub - schoolutilities/react-query-example
Contribute to schoolutilities/react-query-example development by creating an account on GitHub.
3 Replies
helpful-purple
helpful-purple4y ago
i can only guess that this is about the schoolutilities-types dependency? That one has react-query as a dependency when it should likely be a peerDependency: https://github.com/schoolutilities/react-query-example/blob/35f060839e1cf2d536de76c21750bfd2a72d8509/package-lock.json#L2803-L2804
GitHub
react-query-example/package-lock.json at 35f060839e1cf2d536de76c217...
Contribute to schoolutilities/react-query-example development by creating an account on GitHub.
helpful-purple
helpful-purple4y ago
you probably have two versions of react-query floating around because of that. One is used by the lib which has the useQuery in them, the other one is in your app which creates the Providers. So the contexts don't match and they don't "see" each other
conscious-sapphire
conscious-sapphireOP4y ago
Thanks for the reply, I just changed the @tanstack/react-query dependency to a peerDependency and checked all versions of react query in the app and they are all the same but it doesn't work. Do you have any other idea how I can fix that? (The new changes are in the repository)

Did you find this page helpful?