Trying to import realm, but getting error: Missing Realm constructor. Did you run "pod install"? (I'm using windows)
Asked Answered
L

4

11

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",

Lownecked answered 31/3, 2022 at 14:40 Comment(4)
Cocoapods is macOS/iOS. Did you run npm install realm in your project directory followed by npm start?Clearsighted
@Clearsighted I did both those things. So I'm not sure why I get that error message to pod installLownecked
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?Willettawillette
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?Ogdon
G
4

Add this package:

npm install realm@hermes

Works for me.

Gunmaker answered 15/7, 2022 at 20:14 Comment(2)
realm@hermes does mot exist such dependencyOgdon
I tested it here and indeed the package is no longer available. Probably the "npm install realm" bug may have been fixed. I no longer have the project to test such a library.Gunmaker
P
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

Predigest answered 28/7, 2023 at 15:10 Comment(0)
I
-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!

Idler answered 6/5, 2022 at 9:18 Comment(1)
The OP mentioned he is on Windows so none of the iOS steps are applicable.Willettawillette
H
-1

run this command: expo run:android

  • you must build your project first
  • and remember realm is working only on production environment
Halmstad answered 7/2, 2023 at 9:38 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.