realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.62k stars 558 forks source link

`await Realm.open` does not seem to work with Node.js and sync enabled #4554

Closed tomduncalf closed 1 month ago

tomduncalf commented 2 years ago

Running the following code in Node results in libc++abi: terminating with uncaught exception of type Napi::Error: domain.enter is not a function

const Realm = require("realm");

const taskSchema = {
  name: "Task",
  primaryKey: "_id",
  properties: {
    _id: "objectId",
    description: "string",
    isComplete: { type: "bool", default: false },
    createdAt: "date",
    userId: "string",
  },
};

const app = new Realm.App({ id: "pbs-test-pwvrg" });

const user = await app.logIn(Realm.Credentials.anonymous());

const realm = await Realm.open({
  schema: [taskSchema],
  sync: {
    user,
    partitionValue: "myPartition",
  },
});

I found that if I change this line to: Function<T>::callback(protected_ctx, protected_callback, protected_this, 2, callback_arguments); (i.e. add protected_this), the error goes away. But I assume this is a symptom of something else being wrong…

That code was last changed in this PR by Mathias to prep for Hermes from June 2021.

I also see the issue on v11.

kneth commented 2 years ago

Your proposed solution makes sense as it sets this to a proper value instead of an empty object ({}).

kneth commented 1 month ago

With v12 out we are rewritten this part of the code base, and I believe that it has fixed the issue.