Sunday, February 18, 2018

React Native - Missing Realm Constructor

Realm is the most famous local database for any mobile platform. It is very easy to use. Another reason of it's popularity is, this database system is faster than other database systems. You can quickly get result if you query on it. This database can be used for Java, Swift, Objective - C, .Net and JavaScript (that means React Native 👍 ) .

But recently React Native developers are facing an error with react native's redbox (Image 1a and Image 1b) while they are importing Realm in their project. The error says  -
Missing Realm constructor. Did you run "react-native link realm"? Please see https://realm.io/docs/react-native/latest/#missing-realm-constructor for troubleshooting
Image 1a: Redbox says
"Missing Realm Constructor" in iOS simulator
Image 1b: Redbox says
"Missing Realm Constructor" in Android device






















I have faced this error when I have upgraded to the latest React Native and Realm. As the error said to go to the link for troubleshooting, I have tried that. But it did not work. After doing a little research I have found out the solution.

But still do not know why it worked. whenever i know the reason i will update this post.

So I just run a command line in terminal of my project's directory. the command line is (Image 2)
rm ./node_modules/react-native/local-cli/core/__fixtures__/files/package.json
Image 2: Running the command line in my project directory


Then I restart the packager. TADA the redbox is gone and the app is running in the device (android) and simulator (iOS) smoothly (Image 3a and Image 3b)

Image 3a: Running app successfully in
iOS simulator
Image 3b: Running app successfully in
android device
























If my post helped you do not forget to give me +1.

UPDATE: If you are using latest React Native and still getting this error may be this command will not work. It will say something "This file could be found." In this case just turn off the packager and re-install the app in your phone. It will work like charm. Still if you have any question just ask me. 

Enjoy your coding journey. 😃

No comments:

Post a Comment