Realm-js: Unhandled JS Exception: Requiring unknown module "node-fetch"

Created on 9 Jul 2018  路  12Comments  路  Source: realm/realm-js

Cannot deploy release on iOS using XCode.

It's running fine in Debug mode but in Release mode app is crash when launching on both device and simulator.

Below is the log:
WARNING: Logging before InitGoogleLogging() is written to STDERR
E0709 21:00:50.978440 201048064 JSCHelpers.cpp:140] Got JS Exception: Requiring unknown module "node-fetch". (/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2)
E0709 21:00:50.979024 201048064 JSCHelpers.cpp:146] Got JS Stack: c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:636
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:566:306
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
exports@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:574:1890
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:553:1318
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:552:133
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:347:412
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:344:191
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:343:151
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:312:165
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:12:77
c@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:809
i@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2:381
global code@/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:961:8
2018-07-09 21:00:50.984 [fatal][tid:main] Unhandled JS Exception: Requiring unknown module "node-fetch". (/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2)
2018-07-09 21:00:50.986925+0700 PasswordManager[36392:361388] Unhandled JS Exception: Requiring unknown module "node-fetch". (/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2)
2018-07-09 21:00:50.989295+0700 PasswordManager[36392:361388] * Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Requiring unknown module "node-fetch". (/Users/hainguyen/Library/Developer/CoreSimulator/Devices/8212D78F-752C-42DE-B6E7-3A5414E12D7B/data/Containers/Bundle/Application/0CB33BCA-B047-42FC-8AE7-81949490A5AB/PasswordManager.app/main.jsbundle:2)', reason: 'Unhandled JS Exception: Requiring unknown module "node-fetch". (/Users/hain...'
*
First throw call stack:
(
0 CoreFoundation 0x00000001104e91e6 __exceptionPreprocess + 294
1 libobjc.A.dylib 0x000000010edd5031 objc_exception_throw + 48
2 PasswordManager 0x000000010dbfb5b1 RCTFormatError + 0
3 PasswordManager 0x000000010dbe69bf __28-[RCTCxxBridge handleError:]_block_invoke + 689
4 libdispatch.dylib 0x00000001151c76cb _dispatch_call_block_and_release + 12
5 libdispatch.dylib 0x00000001151c8709 _dispatch_client_callout + 8
6 libdispatch.dylib 0x00000001151d2708 _dispatch_main_queue_callback_4CF + 1279
7 CoreFoundation 0x00000001104abc99 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
8 CoreFoundation 0x000000011046fea6 __CFRunLoopRun + 2342
9 CoreFoundation 0x000000011046f30b CFRunLoopRunSpecific + 635
10 GraphicsServices 0x0000000117dc9a73 GSEventRunModal + 62
11 UIKit 0x0000000112f0e057 UIApplicationMain + 159
12 PasswordManager 0x000000010dbd0f90 main + 80
13 libdyld.dylib 0x000000011523d955 start + 1
14 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Version of Realm and Tooling

  • Realm JS SDK Version: 2.12
  • React Native version: 0.56.0
  • Client OS & Version: iOS 11.4
  • Which debugger for React Native: XCode 9
O-Community P-1-Required T-Bug

Most helpful comment

I had the same problem. I downgraded React-Native but left realm at 2.13..

This is what i did: react-native init --version="0.55.4" RN0554 to create a new react-native project and replaced the relevant dependencies from the generated package.json into my project. Then rm -rf node_modules and npm install.

Here is the 0.55.4 package.json:
{ "name": "RN0554", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.3.1", "react-native": "0.55.4", "realm": "^2.13.0" }, "devDependencies": { "babel-jest": "23.4.0", "babel-preset-react-native": "4.0.0", "jest": "23.4.1", "react-test-renderer": "16.3.1" }, "jest": { "preset": "react-native" } }

This fixes the problem for now.

All 12 comments

node-fetch shouldn't be included in a RN app. How do you include Realm in your app? Did you npm install realm --save or do you use Cocoapods?

This happened to me also after upgrading RN from 0.55.4 to 0.56.0 and Realm from 2.10.0 to 2.12.0.

It has most likely something to do with this react native issue where fetch is missing:

https://github.com/facebook/react-native/issues/19827

Upgrading to react-native-babel-preset to version 5.0.2 fixed the problem for me.

@kneth: thanks for your reply. Yes, I installed it using command npm install realm --save. Then I write js file realm.js

import Realm from 'realm';
import { AccountSchema } from './schema/AccountSchema';

export default realm = new Realm({
  schema: [AccountSchema],
  schemaVersion: 5,
});

then I imported realm in epics file and use it like this

import realm from '../../realm/realm';
...
export const getAccountEpic = action$ =>
  action$.ofType(GET_ACCOUNT)
    .map(action => {
      let allAccounts = realm.objects('Account');
      let accountList = allAccounts;
      if (action.payload) {
        accountList = allAccounts.filtered(`host CONTAINS "${action.payload}" OR username CONTAINS "${action.payload}"`)
      }
      accountList = accountList.sorted('copyCount', true);
      return getAccountSuccess(accountList);
    })
  ;

uncomment the realm import and related realm statements then it's running fine

@plouh : thanks but upgrading react-native-babel-preset to 5.0.2 does not help in my case.

It happens to me too :(

screenshot_20180712-132943

It appears that RN 0.56.0 comes with some new challenges.

Downgrading to RN 0.55.4 & Realm to 2.10.0 for a while :(

I had the same problem. I downgraded React-Native but left realm at 2.13..

This is what i did: react-native init --version="0.55.4" RN0554 to create a new react-native project and replaced the relevant dependencies from the generated package.json into my project. Then rm -rf node_modules and npm install.

Here is the 0.55.4 package.json:
{ "name": "RN0554", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.3.1", "react-native": "0.55.4", "realm": "^2.13.0" }, "devDependencies": { "babel-jest": "23.4.0", "babel-preset-react-native": "4.0.0", "jest": "23.4.1", "react-test-renderer": "16.3.1" }, "jest": { "preset": "react-native" } }

This fixes the problem for now.

Any updates on this? We can't use Realm with the current RN version for more than a month.

Again, I've been using Realm.js 2.12-2.14 successfully with RN 0.56.0 since July by simply setting the
babel-preset-react-native to 5.0.2

devDependencies: {
    "babel-preset-react-native": "~5.0.2",
    ....
}

I works both ios and android, simulators and real devices.

Try removing your lock files and node_modules before trying again.

@plouh , I've upgraded to babel-preset-react-native 5.0.2 a long time ago too, but it didn't help.

BTW, I think I've found a solution! Production build no longer crashes after I moved my realm initialisation (import and other stuff) from index.js to App.js. Related issue:
https://github.com/facebook/react-native/issues/19827

That's true! I have a bare-bones index.js because the app itself is written in TypeScript and index.js only renders the App and does nothing else.

Looks like workarounds or fixes has been found. Closing for now.

Was this page helpful?
0 / 5 - 0 ratings