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

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



Solution 1:[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!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Chris