V4 does not log anything in react-native even when not in production #4017
Send to my agentDescribe the bug#
When using react-query v4 with react-native, nothing is logged to the console, even when during development.
For instance when a query function throws an error, the error is not logged.
Your minimal, reproducible example#
https://snack.expo.dev/@matthieugc/react-query-v4-no-logs-repro
Steps to reproduce#
Have a query that throws an error
Expected behavior#
Expected: the error is logged by react-query Happening: nothing is logged
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
- React Native 0.69.3
react-query version#
4.0.10
TypeScript version#
No response
Additional context#
Here's why this seems to be happenning:
The package.json for react-query (and query-core) v4 contains these fields:
And metro, the react-native bundler, uses the browser field in priority when it's available
→ For react-query, it points to the UMD production build, where the default logger calls have been removed during bundling
Yeah. I think that many bundlers prefer
browserfield when available (webpack docs). And it should not be an UMD build, but browser specific build. IE. That does not contain any node specific code. So i think we need to remove it so those bundlers will fall back to other entries. I will be able to do that begining of next week, unless someone else makes that so we could do another pre-release.TkDodo added labelsesm
Same problem here, except with React JS.
@matthieugicquel could you check if problem persists in https://github.com/TanStack/query/releases/tag/v4.0.11-beta.5?
@DamianOsipiuk The logging problem is fixed in this release, thanks!
(Note for other people who may try to install it: I had to manually install the right version of query-core since it would resolve to 4.2.1 instead of the beta version)
By the way I noticed that the
.nativefiles in the codebase are still not getting included, which is logical since react-query come already bundled.For instance the logger file is not used. I'm not sure this one is needed anymore since recent versions of react-native (or expo, not sure) don't have the fullscreen red box that justified it.
But maybe not having the one for batchedUpdates will cause issues?
(Note for other people who may try to install it: I had to manually install the right version of query-core since it would resolve to 4.2.1 instead of the beta version)
yeah I fixed the release script, but it still depends on version with
^, so:"@tanstack/query-core": "^4.0.11-beta.5",and
4.2.1does satisfy that. I think I'll change this again to depend on strict versions, so that downgrading is also possible. Thanks for pointing that out.I tried to install
^4.0.11-beta.5in React JS (I'm using React 18.2.0 & Next 12.2.5) and still don't get any logs in development mode. Devtools are showing up though. Perhaps its not even related with the React Native problem. Should I create a new issue?@vanniewelt can you show this in a codesandbox reproduction please?
By the way I noticed that the .native files in the codebase are still not getting included, which is logical since react-query come already bundled.
Did it work previously? How was it attached at build time? @TkDodo
I tried to install ^4.0.11-beta.5 in React JS (I'm using React 18.2.0 & Next 12.2.5) and still don't get any logs in development mode. Devtools are showing up though. Perhaps its not even related with the React Native problem. Should I create a new issue?
@vanniewelt Make sure you also manually specify
"@tanstack/query-core": "^4.0.11-beta.5",Cause newer version is available and it installs the newest one.@vanniewelt can you show this in a codesandbox reproduction please?
@TkDodo Unfortunately, I wasn't able to reproduce this in codesandbox with simple react app. However, I created demo repository with Next.js: https://github.com/vanniewelt/react-query-no-logging-error-demo
Make sure you also manually specify
"@tanstack/query-core": "^4.0.11-beta.5",Cause newer version is available and it installs the newest one.@DamianOsipiuk I tried it and no luck
I think the issue lies here:
I have fixed
package.jsonto not use^package range, but still...
So it's due to
react-queryhaving a dep on4.2.1due to^@TkDodo

Did it work previously? How was it attached at build time? @TkDodo
I do not know, but this seems to be a separate issue. Can we move it out of this discussion please?
"@tanstack/query-core": "^4.0.11-beta.5",
You actually have to specify exact versions. This beta thing is tricky because we have already released 4.2.1, and if you say you want something that is "compatible with 4.0.11-beta.5", you will still get
4.2.1, because it's "larger than" the beta and it thus satisfies the constraint.you can easily see that by inspecting node_modules. This will all go away once we release the beta.
@TkDodo Unfortunately, I wasn't able to reproduce this in codesandbox with simple react app. However, I created demo repository with Next.js: https://github.com/vanniewelt/react-query-no-logging-error-demo
This is also the problem with your repo because you don't have strict versions specified. If I pin the versions in you repo, error logs work in dev mode:

I would consider this issue done as soon as we release the beta.
@DamianOsipiuk we can release a new beta with the fixed release script if you think it matters? It should have strict versions as dependencies.
@TkDodo Yes, we can also bump the version of beta tag forcefully via actions menu to be greater than current main version. Whatever works for you.
okay,
v4.3.0-beta.0incoming@TkDodo Ah I see, thanks for explanation.
After upgrading to
v4.3.0-beta.0it works! So we can probably close the issue.TkDodo closed this
TkDodo added labelsreleased on @beta
Sign in to join this conversation.
thanks for the analysis. @DamianOsipiuk is this another thing for our bundling changes? I know you mentioned that we should remove the
browserfield altogether ?