[V4] Error in react-native: Unable to resolve module react-dom in 4.3.x (4.2.x unaffected) #4142
Send to my agentDescribe the bug#
With a brand new react-native project, adding react-query produces a Unable to resolve module react-dom error. The issue is that in the build version of setBatchedUpdatesFn.js (build/lib/setBatchedUpdatesFn.js) it is specifically importing reactBatchedUpdates.js with the .js extension (var reactBatchedUpdates = require('./reactBatchedUpdates.js');). In order for Metro (the react-native bundler) to correctly import reactBatchedUpdates.native.js, the import in setBachedUpdatesFn.js needs to be var reactBatchedUpdates = require('./reactBatchedUpdates'); without the file extension.
I am unsure of which build step is producing the output (babel?) or the correct way to fix it, but at the moment all 4.3.x releases are broken in react-native.
Manually editing node_modules/@tanstack/react-query/build/lib/setBatchedUpdatesFn.js to remove the .js extension in the require (var reactBatchedUpdates = require('./reactBatchedUpdates');) makes everything work.
Your minimal, reproducible example#
https://github.com/gorbypark/rctqueryimportbug
Steps to reproduce#
git clone https://github.com/gorbypark/rctqueryimportbugcd rctqueryimportbugyarnnpx pod-install(skip this if android)yarn iosoryarn android- See the error
Expected behavior#
Correctly imported files.
How often does this bug happen?#
Every time
Screenshots or Videos#

Platform#
Tested on macOS in the iOS simulator using a react-native 0.70.0 project created using npx react-native@latest init rctqueryimportbug --template react-native-template-typescript
react-query version#
4.3.1
TypeScript version#
4.8.2
Additional context#
No response
TkDodo added labelsbug
TkDodo added labelsreact-native
TkDodo added labelshelp wanted
Just installed 4.3.3 - same issue
You can add react-dom as a dependency to your own project as a temporary fix if needed, or use this patch package
diff --git a/node_modules/@tanstack/react-query/build/lib/setBatchUpdatesFn.js b/node_modules/@tanstack/react-query/build/lib/setBatchUpdatesFn.js index 281ab22..a009d8e 100644 --- a/node_modules/@tanstack/react-query/build/lib/setBatchUpdatesFn.js +++ b/node_modules/@tanstack/react-query/build/lib/setBatchUpdatesFn.js @@ -1,7 +1,7 @@ 'use strict'; var queryCore = require('@tanstack/query-core'); -var reactBatchedUpdates = require('./reactBatchedUpdates.js'); +var reactBatchedUpdates = require('./reactBatchedUpdates'); queryCore.notifyManager.setBatchNotifyFunction(reactBatchedUpdates.unstable_batchedUpdates); //# sourceMappingURL=setBatchUpdatesFn.js.mapTkDodo closed this
Sign in to join this conversation.
Just installed 4.3.3 - same issue