-
-
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
Thirdparty library with nextJS and @tanstack/react-query
: No QueryClient set
#4346
Comments
hmm, I don't have an immediate answer right now, just wanted to let you know that I'm successfully using the same pattern with nextJs and trpc:
things work fine. maybe one difference is that zodios only creates cjs, while trpc creates esm as well? |
Yes, i think that could be the issue here. So i Can try to generate an esm package for zodios and keep you informed of the result. |
Having a similar issue going from 4.2.3 to 4.3.x. I have a library that has query and a peerdep and uses tsup to build cjs and esm. My NextJS has shows the same error and OP. |
@OliverDudgeon in the mean time you can use the workaround i referenced here : ecyrbe/zodios#191 |
Same issue here! +1 to this! Thank you @ecyrbe for you help! |
so i had another issue with bundle sizes on zodios with nextjs and a user made me think about bundle anlyzer. Here the result for this issue : As you can see, webpack is effectively bundling both mjs and cjs packages together when a third party library in only using cjs.
@TkDodo if you know a bundler guru ? or call for help on twitter ? |
So i guess this makes it an issue of I guess you can close. |
@TkDodo i found an opened issue on nextjs that indicates the fault is definitively on nextjs bundler : vercel/next.js#35112 |
Thanks @ecyrbe for looking into this. This is easily one of my least favourite parts of the js ecosystem 😅 |
@TkDodo for information, the issue is still there after zodios migration to esm. If you want i can come up with a PR to also add a note on react-query docs, just tell me. |
Not sure what the wording would be for us, but feel free to give it a try 👍 |
@TkDodo So this was an adventure, but it's now also fixed on zodios with correct esm exports (i did not add exports at first in Indeed, the issue is transitive. Now that i fixed this, a library using zodios with cjs only package will have the issue. The issue seems to be when a library does not add exports webpack will use the library main entry resolution for it and it's peer dependencies. Meaning in the case of zodios, it was using esm on app and cjs on lib. So to fix this, you need to add a So it'll try to create a speech about bundling that could be used for both |
Describe the bug
Hello,
Since
@tanstack/react-query
v4.3.0 (ESM support) has issues with third party libraries that encapsulate react-query when using it with nextJS (maybe other stacks also, but this is confirmed for nextjs at least)An example is with
@zodios/react
v10 (that added support for `@tanstack/react-query v4)The error message we get is :
Error: No QueryClient set, use QueryClientProvider to set one
Your minimal, reproducible example
https://stackblitz.com/edit/github-ke9tby-8mxjkp?file=package.json
Steps to reproduce
V4.2.3, no bug: https://stackblitz.com/edit/github-ke9tby?file=package.json
V4.3.0, with bug: https://stackblitz.com/edit/github-ke9tby-8mxjkp?file=package.json
@tanstack/react-query
as a peerdependancy and generates ES6 cjs packageMy guess is a combined bug of webpack with esm and the way
@tanstack/react-query
bundles esm + cjs packages.Expected behavior
No error should happen
How often does this bug happen?
Every time
Screenshots or Videos
No response
Platform
react-query version
all versions of
@tanstack/react-query
> v4.3.0TypeScript version
v4.8.4
Additional context
No response
The text was updated successfully, but these errors were encountered: