0

Hi I can't build my next14 + react query + ky project. I want to consume a REST API with react query inside my next14 project. It works perfectly in dev mode, but when I try to build I get an error basically saying : Error: No QueryClient set, use QueryClientProvider to set one. I set a QueryClientProvider in layout.tsx file as said here : https://tanstack.com/query/v4/docs/framework/react/guides/. Here is an OSS reproduction of this bug with details about the issue in the README : https://github.com/Courtcircuits/next14-react-query-error. I've been battling with this for two days and found no solution on StackOverflow or next's github issue

I tried to restart the project from scratch, tried to install different versions of @tanstack/react-query.

3
  • Hey Tristan, there are some guidelines on how to craft a good question on Stack Overflow – notably here, it's important that you provide a minimum reproducible example of the problem you're experiencing and the relevant code here. Links out to external sources get stale after a time, and it's hard to troubleshoot that way. Commented Aug 13, 2024 at 16:53
  • Please provide enough code so others can better understand or reproduce the problem. Commented Aug 13, 2024 at 18:31
  • Hey @brandonscript, I didn't know about the external link thing, next time I'll provide enough code ! Someone helped me fix the problem ! The issue was that I was using the app router AND the pages router because I wanted to separate my ui from my business logic. Now it's fixed, thanks for your advice Commented Aug 14, 2024 at 15:40

1 Answer 1

2

I finally fixed the problem. Actually the problem was not related to react query but to a bad usage of next router. I had two folders :

/app
/pages

My error was that I wanted to put my business logic and ui code in /pages without these files being rendered. I wanted my /app to be the only folder rendered. Therefore be careful when naming your folders in Next, /app and /pages are used by Next !

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I faced the same issue. I didn't realise I had organised my templates inside a /pages folder. Force of habit, I guess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.