New Realm.App({ id: appId }) produces an empty object

Hi everyone!

I’m using Realm for the first time for a React Native (created via react-native init) project, and I’m a bit confused as to why new Realm.App({ id: appId }) produces an empty object {} despite passing in the correct appId.

I’ve installed Realm via yarn add realm@10.0.0-beta.9

If anyone has encountered this problem or has any advice, I’d definitely appreciate any suggestions. Thank you!

Hi @Jerry_Wang,

The syntax you are using to initiate your realm client seems to be for realm-web react

and not the react native sdk:

https://docs.mongodb.com/realm/web/react-web-quickstart/

Can you verify you are using correct ways to initialize client for your imported sdk type:

Let me know if this solved the issue
Pavel

Same issue here. After analysis, I guess this is import issue where no modules from realm is actually imported. if I do import like

import Realm, {App} from 'realm';

and try creating app with

new App(appconfig);

throws undefined is not constructor.

Checked the source of realm, seems to be fine. but not mapping to declarations/exports ?

Hi @Jerry_Wang and @Pravin_kumar,

Please check the node js and react prerequisites:

What is the node and react version you use?

Best
Pavel

I have verified the official docs, git-hub docs. But no luck. I am stuck

“react”: “16.13.1”,
“react-native”: “0.63.2”,
“realm”: “^10.0.0-beta.12”

Hi @Pravin_kumar,

Please open a MongoDB support case or talk with support on the chat visible on the right lower side of atlas project.

Best
Pavel

I’ve found that it’s usually not possible to console.log ANY Realm objects.

For example if you authenticate for a realm app and get the user object back, you will not be able to print it.

e.g. something like
const user = app.loginAnonymous(Realm.Credentials.anonymous());

then
console.log(user); you will get {}. However if you do console.log(user.id) you will get a value.

This seems to be a known bug, see e.g. Improve the output from console.log of objects and collections on Node.js · Issue #2758 · realm/realm-js · GitHub

It’s unfortunately a pretty major issue. My workaround has been to go to the reference documentation for the SDK. Index

Note that this documentation is one version behind the latest release and the whole thing is in Beta.

@Pavel_Duchovny,

Thanks for getting back to me!

It looks like object has enumerable or hidden members?

Printing out the object after JSON.stringify-ing it results in an empty object, but I can call app.logIn() just fine. The user object app.logIn() produces is also empty {}, but logging user.id prints out a UUID string, so I’m not quite sure why printing the user object would show an empty object {}. Attempting to print the object’s keys and enumerable properties results in empty arrays, as well. Is this intended behavior?

Also, with regards to the app initialization – the typescript definitions seem like they don’t accept a “timeout” or “app” parameter, but including them doesn’t throw any errors or change any behavior from initial testing, so I’m not sure whether they’re required or not for React Native.

Hopefully these help others who are experiencing similar issues!

it is not about the empty object. The Realm.App constructor is not working. throws “undefined is not a constructor” error.

Hi Jerry,

Im experiencing the same issue - can access the property but the objects seems empty.
Seems like mongoDB return the object with all properties non-enumerable.
Did you find a way to fix that ?