Skip to content
Source
Sign inSign up
TanStack/query

[V4] Error in react-native: Unable to resolve module react-dom in 4.3.x (4.2.x unaffected) #4142

Send to my agent
Closedgorbypark(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe 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

  1. git clone https://github.com/gorbypark/rctqueryimportbug
  2. cd rctqueryimportbug
  3. yarn
  4. npx pod-install (skip this if android)
  5. yarn ios or yarn android
  6. See the error

Expected behavior

Correctly imported files.

How often does this bug happen?

Every time

Screenshots or Videos

Screen Shot 2022-09-11 at 12 06 44 PM

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

  1. TkDodo added labelsbug

  2. TkDodo added labelsreact-native

  3. TkDodo added labelshelp wanted

  4. Just installed 4.3.3 - same issue

  5. 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.map
  6. TkDodo closed this

Sign in to join this conversation.