You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@sachinraja I can confirm that 4.0.11-beta.0 doesn't work with react-scripts v4. Here is an (older) repo of mine that uses v4 of react-scripts, and I've merely switched from 4.1.0 where it works (but doesn't render devtools at all as per the issue) to the beta:
@DamianOsipiuk I tried the latest beta (4.0.11-beta.4) with react-scripts v4 and it now fails with:
Failed to compile.
./node_modules/@tanstack/react-query-devtools/build/lib/index.mjs
Can't import the named export 'Fragment' from non EcmaScript module (only default export is available)
So far when i have played with it i was unable to make it work for webpack 4 while maintaining support for other bundlers.
There is additional config needed for webpack 4 to make it work, which will be a pain for react-scripts users due to webpack config being inaccessible without third party tools.
I have one more idea which i will test when i will have some time, via exports.node.
All other ideas to solve this problem appreciated.
however, that import path is not great. Could we somehow alias that to '@tanstack/react-query-devtools/production' ?
I can reintroduce that export, but it will only work with bundlers that fully supports exports, like vite.
react-scripts would have to import the ugly one
Unfortunately the issue with @tanstack/react-query-devtools/production is typescript bug that i have mentioned previously. So typescript will yell at you that it does not have type declarations, even though vite will compile successfully.
rendering the production devtools doesn't actually work in a production build. Here is the code:
I'm not sure about this particular piece of code but it worked for me with the following with react-scripts 4:
import{QueryClient,QueryClientProvider}from"@tanstack/react-query";// import { ReactQueryDevtools } from "@tanstack/react-query-devtools";importReactfrom"react";import{Example}from"./Example";constqueryClient=newQueryClient();constReactQueryDevtools=React.lazy(async()=>{constdevtools=awaitimport("@tanstack/react-query-devtools/build/lib/index.prod.js");return{default: devtools.ReactQueryDevtools,};});functionApp(){return(<QueryClientProviderclient={queryClient}><Example/><ReactQueryDevtoolsinitialIsOpen/></QueryClientProvider>);}exportdefaultApp;
I can reintroduce that export, but it will only work with bundlers that fully supports exports, like vite.
react-scripts would have to import the ugly one
if that's fine with you, i think its okay.
I'm not sure about this particular piece of code but it worked for me with the following with react-scripts 4:
you are right! it works fine with react-scripts 4, but not with react-scripts 5. I up/downgraded back and forth for testing, and when I wrote the above summary, I missed that.
@DamianOsipiuk that's an interesting find! we need the isServer check because useLayoutEffect doesn't work on the server. However, I think we could simply always useEffect here? Or maybe it also works if we change isServer to be a function, because then the result cannot be optimized away:
@DamianOsipiuk toggling devtools now works in react-scripts v5. The typescript import issue is still there, but I think for now, I'll just add documentation that you can import with the long path.
@TkDodo Version 5.0.0-beta-alpha.56 complains for lazy loding dev tools for production, same goes for lower version, at least I've tried 35 and it's the same... Tried adding index.d.ts file with declare module '@tanstack/react-query-devtools/build/lib/index.prod.js', not helping too...
Module not found: Error: Package path ./build/lib/index.prod.js is not exported from package /home/igor/projects/ToolbarApp/node_modules/@tanstack/react-query-devtools (see exports field in /home/igor/projects/ToolbarApp/node_modules/@tanstack/react-query-devtools/package.json)
Activity
TkDodo commentedon Jul 20, 2022
@sachinraja FYI
TkDodo commentedon Aug 11, 2022
let's try to keep discussion about ESM support here :)
I tried out
4.0.11-beta.0and it works fine in our simple example, but that one usesvite:There have been reports on discord that this version "breaks the app", but we'd need more info and try out more bundlers I guess.
cc @DamianOsipiuk
sachinraja commentedon Aug 11, 2022
@TkDodo Yeah if they share reproductions or at least error messages, I can look into it.
TkDodo commentedon Aug 12, 2022
@sachinraja I can confirm that
4.0.11-beta.0doesn't work with react-scripts v4. Here is an (older) repo of mine that uses v4 of react-scripts, and I've merely switched from4.1.0where it works (but doesn't render devtools at all as per the issue) to the beta:what I'm seeing when I run it is this:
I can also confirm that removing the rendering of the
<ReactQueryDevtools initialIsOpen />makes the error go away.TkDodo commentedon Aug 12, 2022
Another thing I found out with @DamianOsipiuk is that the size of the beta is 5x times too large:
https://bundlephobia.com/package/@tanstack/react-query@4.0.11-beta.0
I think @DamianOsipiuk mentioned that react-dom is included because it wasn't specified as external. Just wanted to note all known issues here :)
sachinraja commentedon Aug 12, 2022
I've seen that Provider error before, it has to do with bundlers picking the cjs format for one package and the same format for the other package.
TkDodo commentedon Aug 18, 2022
@DamianOsipiuk I tried the latest beta (4.0.11-beta.4) with
react-scriptsv4 and it now fails with:DamianOsipiuk commentedon Aug 18, 2022
Hmm it seems that it now complains about
esm+cjsinterop. At least it's picking up correct entry right now.Will take a look at that.
DamianOsipiuk commentedon Aug 22, 2022
So far when i have played with it i was unable to make it work for webpack 4 while maintaining support for other bundlers.
There is additional config needed for webpack 4 to make it work, which will be a pain for
react-scriptsusers due to webpack config being inaccessible without third party tools.I have one more idea which i will test when i will have some time, via exports.node.
All other ideas to solve this problem appreciated.
TkDodo commentedon Aug 23, 2022
can I ask all interested parties to please try out the latest and greatest beta version:
https://github.com/TanStack/query/releases/tag/v4.3.0-beta.3
on my create-react-app v4, I see no problems now:
TkDodo commentedon Aug 23, 2022
One thing that doesn't work is the lazy import of the devtools in production. looking at our
exports, there should be a.productionentry point:query/packages/react-query-devtools/package.json
Lines 15 to 34 in 2452ec1
However, if I'm trying:
I'm getting the error:
I tried this with create-react-app v4 and v5
TkDodo commentedon Aug 23, 2022
I also tried out our nextJs example and it works fine with the beta:
https://codesandbox.io/s/recursing-wind-vo3htt
TkDodo commentedon Aug 23, 2022
okay one more tiny thing:
it seems that direct dependencies of the devtools are now included in the production bundle:
https://unpkg.com/@tanstack/react-query-devtools@4.3.0-beta.3/build/umd/index.production.js
I can see
useSyncExternalStoreandmatch-sorter-utilsbeing bundled.this is also visible in bundlephobia:
https://bundlephobia.com/package/@tanstack/react-query-devtools@4.3.0-beta.3
4.2.1 has
317Bwhile 4.3.0-beta.3 has8.2kB6 remaining items
DamianOsipiuk commentedon Aug 24, 2022
I can reintroduce that export, but it will only work with bundlers that fully supports exports, like vite.
react-scripts would have to import the ugly one
Unfortunately the issue with
@tanstack/react-query-devtools/productionis typescript bug that i have mentioned previously. So typescript will yell at you that it does not have type declarations, even though vite will compile successfully.I'm not sure about this particular piece of code but it worked for me with the following with react-scripts 4:
TkDodo commentedon Aug 25, 2022
if that's fine with you, i think its okay.
you are right! it works fine with react-scripts 4, but not with react-scripts 5. I up/downgraded back and forth for testing, and when I wrote the above summary, I missed that.
DamianOsipiuk commentedon Aug 27, 2022
@TkDodo
additional import - #4090
not sure what could be the problem but you core works for me both for react scripts 4 and 5Edit. It does not work with
React.lazySo it seems, when you change
to
or
It starts working again...
TkDodo commentedon Aug 28, 2022
@DamianOsipiuk that's an interesting find! we need the
isServercheck becauseuseLayoutEffectdoesn't work on the server. However, I think we could simply alwaysuseEffecthere? Or maybe it also works if we changeisServerto be a function, because then the result cannot be optimized away:?
TkDodo commentedon Aug 28, 2022
@DamianOsipiuk I've switched to only using
useEffectand removed theisServercheck completely:I'll quickly re-test this with the latest beta. This was the last issue, right? If that works, we would be ready to merge?
TkDodo commentedon Aug 28, 2022
@DamianOsipiuk toggling devtools now works in react-scripts v5. The typescript import issue is still there, but I think for now, I'll just add documentation that you can import with the long path.
DamianOsipiuk commentedon Aug 28, 2022
@TkDodo Typescript issue will go away if you change the
moduleResolutiontoNodeNext. We could potentially add that to docs.And yes, i think that was the last issue.
TkDodo commentedon Aug 28, 2022
I added this paragraph, is that about right?
5e145fc
DamianOsipiuk commentedon Aug 28, 2022
Yup, although i think that TS 4.7 is required.
TkDodo commentedon Aug 28, 2022
I got 4.5 from their docs:
DamianOsipiuk commentedon Aug 28, 2022
I was more thinking about this https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#package-json-exports-imports-and-self-referencing 😉
TkDodo commentedon Aug 28, 2022
okay, I updated it: 40c3491
igortas commentedon Jun 6, 2023
@TkDodo
Version 5.0.0-beta-alpha.56complains for lazy loding dev tools for production, same goes for lower version, at least I've tried 35 and it's the same... Tried adding index.d.ts file withdeclare module '@tanstack/react-query-devtools/build/lib/index.prod.js', not helping too...Module not found: Error: Package path ./build/lib/index.prod.js is not exported from package /home/igor/projects/ToolbarApp/node_modules/@tanstack/react-query-devtools (see exports field in /home/igor/projects/ToolbarApp/node_modules/@tanstack/react-query-devtools/package.json)
TkDodo commentedon Jun 6, 2023
That's more something for @ardeora