realm-js: The dreaded "Missing Realm constructor" still

This is obviously a commonly occurring issue, since you have it linked in the docs. Is this a heisenbug that won’t go away?

I’m only testing integration with import Realm from 'realm'. In iOS simulator, no crash or issue happens. But once built on XCode and run on device, my app would crash on launch, with this XCode console output:

*** Terminating app due to uncaught exception 'RCTFatalException: Unhandled JS Exception: Missing Realm constructor. Did you run "react-native link realm"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting', reason: 'Unhandled JS Exception: Missing Realm constructor. Did you run "react-nativ..., stack:
a@577:484
<unknown>@577:926
n@2:553
<unknown>@371:7765
n@2:553
<unknown>@12:435
n@2:553
i@2:266
global code@600:9
'
*** First throw call stack:
(0x183ec6fe0 0x182928538 0x183ec6f28 0x10017532c 0x10016f758 0x183ecce80 0x183dc22c4 0x183dc6e9c 0x1001731f8 0x1001c0cfc 0x1001c0b68 0x101029a50 0x101029a10 0x1010372e8 0x10102d634 0x101037810 0x101039630 0x10103939c 0x182f87100 0x182f86cac)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

Version of Realm and Tooling

  • Realm JS SDK Version: 1.8.3
  • Node or React Nattive: node 8.1.3, RN 0.46.1
  • Client OS & Version: iOS 10 built on MacOS 10.12.5
  • Which debugger for React Native: None (on device, building from XCode)

I’m also using CocoaPods (for react-native-firebase). I’m seeing some other issues filed that have issue with Pods too, if this is a known pattern that Realm doesn’t play nice with Pods? I’m not linking Realm with Pods FYI, I’m following the docs and linked with react-native link.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (2 by maintainers)

Most upvoted comments

Does anyone have the problem ?

Me naturally since I first posted this, on RN 0.46.1 (iOS). I haven’t tested again since updating RN, now latest at 0.46.4.

This is a showstopper that needs some TLC.

That solution doesn’t work well for defining schemas by extending Realm.Object(). While evaluating, realm isn’t loaded in and the constructor has not defined realm yet, so the value of realm is null. Do you have a solution for that?

@scue - The way we fixed it was to set the realm const to null at load: const Realm = null; Then, after the app has fully loaded (we used the login function) call: if (Realm === null) { Realm = require(‘realm’); };

It must be some sort of timing issue…because we found a solution that was satisfactory to our needs we didn’t investigate any further.

@jbcullis I got the same problem, app will randomly exit, and crash log is:

RCTFatalException: Unhandled JS Exception: Missing Realm constructor. Did you run "react-native link realm"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting

I already read the realm docs many times, check all steps, and upgrade realm to "realm": "^2.0.4", it still crash randomly, my test step:

  1. start app
  2. double click home button, kill app
  3. start app again

Crash rate: 6/70.

RN Version: "react-native": "0.49.3",

Please check out #1436 - maybe it solves your issue, too 😉

@Techwolf12 - That looks to be someone that hasn’t linked the library, I have verified all setup is in place and as stated above, on launching the app (test flight) the app will randomly exit but if you double click home button you’ll see the app sitting there in the background.

Nevermind on last comment. RN itself seems to be culprit and fix: https://github.com/facebook/react-native/issues/14382#issuecomment-313163119