10

I'm making a mobile application with react native. I want to use Realm (mongodb).
So after running:

npm install realm

realm was correctly added in the "node_modules" and I tried to import realm with:

import Realm from "realm";

If I do npm start and test the app, I get to following error message:

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

I'm using windows and testing the app on an android device. Earlier questions about this matter on the internet suggested it is in my situation not needed to do "pod install".

I also tried to autolink realm, with:

react-native link realm

But then I get the warning:

warn Calling react-native link [packageName] is deprecated in favor of autolinking. It will be removed in the next major release. Autolinking documentation: https://github.com/react-native-community/cli/blob/master/docs/autolinking.md (node:26016) Warning: Accessing non-existent property 'padLevels' of module exports inside circular dependency (Use node --trace-warnings ... to show where the warning was created)

  1. Does that mean that the autolinking is not successful, because autolinking will be removed in the next release?

  2. Does any of you have suggestions on how I can successfully import Realm in my react native project?

Here are some of the dependency versions:

"expo": "^44.0.0",
"realm": "^10.14.0"
"react-native": "0.64.3",

JeffreyChong
  • 167
  • 1
  • 2
  • 11
  • Cocoapods is macOS/iOS. Did you run `npm install realm` in your project directory followed by `npm start`? – Jay Mar 31 '22 at 18:13
  • @Jay I did both those things. So I'm not sure why I get that error message to pod install – JeffreyChong Mar 31 '22 at 19:48
  • I am trying to run an android only app on my Linux machine (using a physical android device) I cannot run any of the ios specific install steps of course. Is that a requirement to use realm? – Taylor A. Leach Nov 12 '22 at 01:54
  • Am also getting same error with latest version of realm(11) and react native (0.70). But only in case of enabling debugging mode. I can run the application without any error for the debugger not enabling the case. But because of this issue can't do step debugging which takes a lot of time for development. is anyone have a solution for this? – Poonam Jan 12 '23 at 09:23

4 Answers4

4

Add this package:

npm install realm@hermes

Works for me.

Community
  • 1
  • 1
0

run this command: expo run:android

  • you must build your project first
  • and remember realm is working only on production environment
0

In case anyone is still looking for an answer.

You cant use Realm with the Expo Go app, the app permits very few packages and anything that's not included in the list wont work. So you have to install expo-dev-client and you have to upload it to EAS to run a development server that you can work with. Takes a bit of setting up but once you manage, it works just like the Expo Go App.

Check out this page on how to set it up https://reactnative.dev/docs/environment-setup

-1

As the error message suggests, you need to install the pod files for realm to work with iOS. Those are the steps:

  1. In your project folder run npm install realm. It adds the npm package to your react native project
  2. In your iOS folder (cd ios) run pod install. It gets all iOS realm libraries and compiles the iOS-part of your npm package and creates the .xcworkspace.
  3. Add the import to your component: import Realm from "realm";
  4. Switch back to your project folder and run your project: react-native run-ios

Hope that solves your problem!

Chris
  • 4,403
  • 4
  • 42
  • 54