react-query v4: useSyncExternalStore error with Create React App #3637
Send to my agentDescribe the bug#
Using react-scripts@4.0.3 (a.k.a. Create React App) does not work with react-query@4.0.0-beta.X. The following is the error that occurs when running the development server:
./node_modules/react-query/lib/reactjs/useSyncExternalStore.mjs
Can't reexport the named export 'useSyncExternalStore' from non EcmaScript module (only default export is available)
Your minimal, reproducible example#
https://github.com/tmm/react-query-debug
Steps to reproduce#
- Clone repo
- Install dependencies
npm i - Run development server
npm start
Expected behavior#
I expected to not get an useSyncExternalStore error
How often does this bug happen?#
Every time
Screenshots or Videos#
Platform#
- OS: macOS
- Browser: Firefox, Chrome
react-query version#
4.0.0-beta.X
TypeScript version#
No response
Additional context#
Reporting based on this comment by TkDodo for https://github.com/tmm/wagmi/issues/398
@hirbod @sachinraja can you maybe also have a look here?
I'm not sure if we're doing some wrong in our imports / exports, or if this is CRA related? We have some examples that run on CRA 3.x and they are fine 🤔
FYI, If I change this to use the default import, like the error suggests, it doesn't complain anymore, however, it also doesn't work at runtime:
This suggests to me that the named re-export is actually correct ?
I am afraid that I am not the best person to answer this. All my knowledge goes down to RN
The error is correct. We need to change
useSyncExternalStore.tsto this:import pkg from 'use-sync-external-store/shim/index.js' export const useSyncExternalStore = pkg.useSyncExternalStoreThis is due to esm/cjs interop. The error isn't in
react-scripts@3because it only uses cjs.Ah yeah, I remember seeing this fix in another repo, I think it was reanimated or react-native-gesture-handler.
thx, I'll make a PR. One more question: is the code for
useSyncExternalStore.native.tscorrect?export { useSyncExternalStore } from 'use-sync-external-store/shim/index.native.js'The metro bundler only picks the cjs path for this package but yeah it should probably also be changed.
TkDodo closed this
TkDodo added labelsv4
:tada: This issue has been resolved in version 4.0.0-beta.17 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
tannerlinsley added labelsreleased on @beta
Sign in to join this conversation.
Same issue here and I'm using windows