Realm-js: Missing Realm constructor. Did you run "react-native link realm"?

Created on 12 Oct 2019  ·  55Comments  ·  Source: realm/realm-js


2019-10-12 18:12:48.003275+0800 mlmlApp[28520:193898] [] nw_socket_handle_socket_event [C5.1:1] Socket SO_ERROR [61: Connection refused]
2019-10-12 18:12:48.008963+0800 mlmlApp[28520:193898] [] nw_socket_handle_socket_event [C5.2:1] Socket SO_ERROR [61: Connection refused]
2019-10-12 18:12:48.017092+0800 mlmlApp[28520:193888] [] nw_connection_get_connected_socket [C5] Client called nw_connection_get_connected_socket on unconnected nw_connection
2019-10-12 18:12:48.017465+0800 mlmlApp[28520:193888] TCP Conn 0x6000020f1680 Failed : error 0:61 [61]
2019-10-12 18:12:48.222 [error][tid:com.facebook.react.JavaScript] Error: Missing Realm constructor. Did you run "react-native link realm"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
2019-10-12 18:12:48.226 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: Error: Missing Realm constructor. Did you run "react-native link realm"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
2019-10-12 18:12:48.253 [error][tid:com.facebook.react.JavaScript] Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)
2019-10-12 18:12:48.256 [fatal][tid:com.facebook.react.ExceptionsManagerQueue] Unhandled JS Exception: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication)

Version of Realm and Tooling

  • Realm JS SDK Version: 3.2.0
  • Node or React Native: 0.61.2
  • Client OS & Version: Mac10.14.6
  • Which debugger for React Native: xCode

I have followed the documentation ‘https://realm.io/docs/javascript/latest/#missing-realm-constructor’ but it not work

O-Community T-Enhancement

Most helpful comment

Good day guys.

image

I am having this error on an android simulator. what's wrong?

All 55 comments

image

Android is ok

error React Native CLI uses autolinking for native dependencies, but the following modules are linked manually:

  • react-native-gesture-handler (to unlink run: "react-native unlink react-native-gesture-handler")
  • react-native-screens (to unlink run: "react-native unlink react-native-screens")
  • realm (to unlink run: "react-native unlink realm")
    This is likely happening when upgrading React Native from below 0.60 to 0.60 or above. Going forward, you can unlink this dependency via "react-native unlink " and it will be included in your app automatically. If a library isn't compatible with autolinking, disregard this message and notify the library maintainers.
    Read more about autolinking: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md

same issue for me as well. android is ok, iOS does not work after upgrading from 0.59.9 to 0.61.2. realm 3.2.0

I believe it is related to #2460 - and we are working on it.

@kneth, so let us know, the developers are waiting for their projects to be developed and so on.

We have identified a bug in v3.2.0, and we hope to have a fix ready tomorrow or Monday. Please use v3.1.0.

I have verified that Realm JS 3.1.0 builds and runs successfully with the latest React Native 0.61.2. The bug @kneth mentions is unrelated to this particular issue. After installing Realm you should perform the manual linking (react-native link realm), until we've fixed https://github.com/realm/realm-js/issues/2460 - but it works if you just proceed as normal, for now.

@Yieron did you update an existing project or start from scratch? Can you try with Realm JS 3.1.0 (which is now latest)?

@kraenhansen, you get it working for both iOS and Android on RN0.61.2 and realm v3.1.0, am I right?

@kraenhansen can you elaborate on how you were able to get RN 0.61.2 working with 3.1.0? It looks like there is still an open bug (https://github.com/realm/realm-js/issues/2562) that contradicts your reply here.

Upon further thought, it appears that the error in https://github.com/realm/realm-js/issues/2562 is caused by using cocoapods to link the project dependencies. Are you still linking react and your other dependencies manually in the Link Binary with Libraries build phase on iOS?

@Yieron did you update an existing project or start from scratch? Can you try with Realm JS 3.1.0 (which is now latest)?

I start from scratch. I will try with Realm JS 3.1.0. I'll give you feedback later.

We have identified a bug in v3.2.0, and we hope to have a fix ready tomorrow or Monday. Please use v3.1.0.

ok,I will try, thank you very much!

@Yieron did you update an existing project or start from scratch? Can you try with Realm JS 3.1.0 (which is now latest)?

My other app uses
image
it is perfect!

@kraenhansen @kneth
Realm JS SDK Version: 3.1.0
Node or React Native: 0.61.2
Client OS & Version: Mac10.14.6
Which debugger for React Native: xCode

npm install --save realm
react-native link realm

the same error.

image
image

@Yieron Please try to clear the build folder and verify that you have installed v3.1.0 (^3.1.0 might have installed v3.2.0).

@Yieron Please try to clear the build folder and verify that you have installed v3.1.0 (^3.1.0 might have installed v3.2.0).

1 I delete node_modules
2 I close all simulators
3 I clean xCode
4 "realm": "^3.1.0",
4 npm install
5 react-native link

I am sure I have installed v3.1.0

When I comment out the following code, I can run it.
// const Realm = require('realm');

// class Person extends Realm.Object { }; //登录用户信息
// Person.schema = {
// name: 'Person',
// primaryKey: 'userID',
// properties: {
// userName: { type: 'string', default: '', optional: false },
// userID: { type: 'string', default: '', optional: false }, //optional:true 等价于 serID: 'string?', // optional property
// }
// }

// export default new Realm({
// schema: [Person],
// schemaVersion: 1
// });

The same error occurs when I let go of the code

Im getting the same error on react-native 0.59.8 so doesnt seem to be related to autolinking

Im getting the same error on react-native 0.59.8 so doesnt seem to be related to autolinking

My other app uses "react-native": "0.60.0", "realm": "^2.29.1", its ok.

if i try to downgrade i end up with
"could not read data from /node_modules/realm/tests/ios/Info.plist': The file “Info.plist” couldn’t be opened because there is no such file."
originating from the RealmJSTests target

I was able to make it work for me.

  1. dependencies: {
    "react": "16.8.6",
    "react-native": "0.60.5",
    "realm": "3.2.0", // 3.3.0 not working
    }

  2. Create file _react-native.config.js_ in root folder (I think this step is not necessary, but it prevent error messages)

module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

In xcode:

  1. Add libraries:
    node_modulesrealm\react-native\ios\RealmReact.xcodeproj
    node_modulesrealm\src\RealmJS.xcodeproj
  1. Deal with issue with signing in target RealmJSTests. I choose the Team for Sign certificate, but I think also the option is simple delete this target.

  2. Link binary from pervious added libraries:
    libRealmJS.a and libRealmReact.a

Thanks this https://github.com/realm/realm-js/issues/2549#issuecomment-539239010 and this https://github.com/realm/realm-js/issues/2460#issuecomment-543905035 messages

I was able to make it work for me.

dependencies: {
"react": "16.8.6",
"react-native": "0.60.5",
"realm": "3.2.0", // 3.3.0 not working
}

  1. Create file _react-native.config.js_ in root folder (I think this step is not necessary, but it prevent error messages)
module.exports = {
    dependencies: {
        'realm': {
            platforms: {
                ios: null,
            },
        },
    },
}

In xcode:

  1. Add libraries:
    node_modulesrealm\react-native\ios\RealmReact.xcodeproj
    node_modulesrealm\src\RealmJS.xcodeproj
  1. Deal with issue with signing in target RealmJSTests. I choose the Team for Sign certificate, but I think also the option is simple delete this target.
  2. Link binary from pervious added libraries:
    libRealmJS.a and libRealmReact.a

Thanks this #2549 (comment) and this #2460 (comment) messages

ok,thanks ,I will try later

@Yieron any results?

@Yieron any results?

No result,I tried, failed

@Yieron any results?
No result,I tried, failed

But it works. Can you make xcode screenshots?

I have verified that Realm JS 3.1.0 builds and runs successfully with the latest React Native 0.61.2. The bug @kneth mentions is unrelated to this particular issue. After installing Realm you should perform the manual linking (react-native link realm), until we've fixed #2460 - but it works if you just proceed as normal, for now.

Could you give an android example? As far as I know I need to disable Hermes engine... Is it enough for successful run in android?

If your problem is on iOS, try:

Close all simulators/device builds
Stop the package manager running in terminal (or better yet, just restart terminal)
Open the ios folder in your app root in finder
Go into the build folder (note: you won’t see this build folder in atom, so just right click ios and click open in finder)
Delete everything inside of the build folder (just move to trash and keep trash around in case you’re worried)
Run react-native run-ios to rebuild the whole thing

Can you provide detailed screenshots of the steps?

I got the same problem too...
I have environment likes below:

nodejs: v10.16.3
react-native-cli: 2.0.1
react-native: 0.61.2
realm: 2.23.0-hotfix.1
os: windows 10 64 bit

and got error:
Error: Missing Realm constructor. Did you run "react-native link realm"?.....

I solved by:

  1. downgrading the realm version from 2.23.0-hotfix.1 to 2.23.0
  2. npm install
  3. cd android & gradlew clean
  4. run android (it was running, the error was gone)
  5. upgrading again from 2.23.0 to 2.23.0-hotfix.1
  6. npm install
  7. cd android & gradlew clean
  8. run android again (it was successfully)

I got the same problem too...
I have environment likes below:

nodejs: v10.16.3
react-native-cli: 2.0.1
react-native: 0.61.2
realm: 2.23.0-hotfix.1
os: windows 10 64 bit

and got error:
Error: Missing Realm constructor. Did you run "react-native link realm"?.....

I solved by:

  1. downgrading the realm version from 2.23.0-hotfix.1 to 2.23.0
  2. npm install
  3. cd android & gradlew clean
  4. run android (it was running, the error was gone)
  5. upgrading again from 2.23.0 to 2.23.0-hotfix.1
  6. npm install
  7. cd android & gradlew clean
  8. run android again (it was successfully)

Android is ok iOS not work

I give up, I used version 2.29.1
finally I succeeded

I give up, I used version 2.29.1
finally I succeeded

Can you provide the steps to how you achieved a successful build?

Having the same issue here and failed to even install or build realm. The hotfix file is not available.

npm install --save realm

> [email protected] install /home/user/app/my.ReactNative/node_modules/realm
> node-pre-gyp install --fallback-to-build

node-pre-gyp WARN Using request for node-pre-gyp https download 
node-pre-gyp WARN Tried to download(404): https://static.realm.io/node-pre-gyp/2.23.0-hotfix.1/realm-v2.23.0-hotfix.1-node-v72-linux-x64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for [email protected] and [email protected] (node-v72 ABI, glibc) (falling back to source compile with node-gyp) 
make: Entering directory '/home/r.../ReactNative/node_modules/realm/build'

... and many build errors follow

$ node -v
v12.13.0
$ react-native -v
react-native-cli: 2.0.1
react-native: 0.61.1

@rasos We don't yet support node v12. Try to downgrade to node v10.

I got it working by: for both iOS AND android

having the auto-linking disabled in the config file

OSX 10.15
RN 0.61.2
REALM 3.2.0

dragged this two XCODE and deleted the test target in RealmJS.xcodeproj

Screenshot 2019-11-01 at 3 09 01 AM

added the libRealmReact.a file in link binaries with libraries

Screenshot 2019-11-01 at 3 15 32 AM

Downgrading to node 10 allowed me to install realm

sudo n 10 
npm install --save realm

https://github.com/realm/realm-js/issues/2582#issuecomment-548282235

@rizwanatta Thank you for the recipe.

@rizwanatta Thank you for the recipe.

I got it working by: for both iOS AND android

having the auto-linking disabled in the config file

OSX 10.15 RN 0.61.2 REALM 3.2.0

dragged this two XCODE and deleted the test target in RealmJS.xcodeproj

Screenshot 2019-11-01 at 3 09 01 AM

added the libRealmReact.a file in link binaries with libraries

Screenshot 2019-11-01 at 3 15 32 AM

image
Do it according to your documents. It's OK. Thank you!

My app uses "react-native": "0.59.0", "realm": "^3.3.0 has the same problem.

@zpz5789 Are you on iOS or Android?

@kneth iOS Platform.

@zpz5789 Could you try to upgrade to v3.4.0? We have added CocoaPod support which could help you.

@kneth I tried installing v3.4.0 now and facing the same issues. Removed all the manual linking code in ios as now we have CocoaPod support.

It might be required to clear the build folder when upgrading.

you should add a migration guide for >3.4.0
I'm still trying to figure it out, but it throws error of double symbols
or shows Missing Realm constructor

It seems that, in addition to @rizwanatta's recipe, libRealm.js must be linked in order to archive for iOS.

As @davidlondono said, if we don't add libRealmReact.a app would be throw an error that missing Realm constructor. And in case libRealmReact.a is added, this is failed to build app with error xxx duplicated symbols .... What should I do now?

@hauhuynh1208 If you are using Realm JS >= 3.4.0, you should use CocoaPod to build for iOS. If you are upgrading from a previous version, it is likely that you need to clear ios/build before building.

@kneth I am using Realm JS 3.1.0 and suddenly experience this error. So I decide to upgrade Realm JS package:

  1. remove realm from package.json
  2. remove ios/build and Podfile.lock
  3. remove yarn.lock and node_modules
  4. yarn cache clean
  5. yarn install
  6. cd ios/ && pod install

It's still fail to build iOS. Android working properly.
P/s As my thread (comment #2634 ), I believe there might be the package conflict

@kneth I am using Realm JS 3.1.0 and suddenly experience this error. So I decide to upgrade Realm JS package:

  1. remove realm from package.json
  2. remove ios/build and Podfile.lock
  3. remove yarn.lock and node_modules
  4. yarn cache clean
  5. yarn install
  6. cd ios/ && pod install

It's still fail to build iOS. Android working properly.

If this is referring to https://github.com/realm/realm-js/issues/2634 - let's keep the conversation there instead of communicating on a closed issue. Thanks! 👍

"react-native": "0.61.2",
"realm": "^3.5.0",

If run $ react-native run-ios - its ok

If run project in xCode to simmulator - Error: Missing Realm constructor. Did you run "pod install"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting

If remove folder ios/build and again run project in xCode - again Error "Missing Realm constructor" and folder ios/build is empty

UPD: Go to xCode menu Product -> Clean Build Folder - Yesssss YO!
Its work

Good day guys.

image

I am having this error on an android simulator. what's wrong?

I fixed it by cleaning the Gradle. Go into the android folder of your react-native app

// the android folder
cd android

// clean
gradlew.bat clean

// when finished
npm run android

you should add a migration guide for >3.4.0
I'm still trying to figure it out, but it throws error of double symbols
or shows Missing Realm constructor

Have this as well

I am also facing the same issue, anyone found some solution ??

I deleted the build directory under the android directory, ran react-native run-android and it cleared up the error.

Was this page helpful?
0 / 5 - 0 ratings