Realm.open throws Error: Can't create protected reference

Opening a simple synced Realm, completely empty data cluster.

The user is authenticated correctly but opening the Realm keeps throwing the Error: Can’t create protected reference: napi_status 1.

I’ve tried with the 10.8.0, 10.9.0 and 10.9.1 versions of the RealmJS sdk on NodeJS.

Hi @Diogo_Nascimento,

Can you please provide a reference of your app (ideally, the Atlas URL of the Dashboard), and a snippet of the code you’re using to open the realm?

It would also help to know the Node.js version

Hi @Paolo_Manna, sorry for the late reply.

The issue seems to be with NodeJS versions 16.12.0 and 17.0.1 I believe, on the current NodeJS LTS version (14.16.0) the issue does not appear.

The only value I found for the Atlas URL was in the connect menu with the following devcluster.wbpip.mongodb.net/todo?retryWrites=true&w=majority.

The code used to connect was the one described in the legacy Realm migration guide.

let app = new Realm.App({
  id: configToUse.appId, // This the identifier shown in the dashboard
  app: {
    name: 'Test',
    version: '0.0.1'
  }
})
const token = '' // The access token, this value is empty on this snippet
const credentials = Realm.Credentials.jwt(token)
app.logIn(credentials)
    .then(user => {
        const config = {
          schema: SCHEMAS,
          path: `realm/mongodb_${app.id}`,
          sync: {
            existingRealmFileBehavior: {
              type: 'openImmediately',
              timeout: 10000,
              timeOutBehavior: 'openLocalRealm'
            },
            newRealmFileBehavior: {
              type: 'downloadBeforeOpen',
              timeout: 10000,
              timeOutBehavior: 'throwException'
            },
            user: user,
            partitionValue: '' // This value is set to a specific value that already is configured in Atlas to exist
          }
        }
        return Realm.open(config).progress((transferred, transferable) => {
          console.log(`Transferable: ${transferable}, Transferred: ${transferred}`)
        })
    })
    .then(realm => {
        realm.schema.forEach(schema => {
          const schemaObjects = realm.objects(schema.name)
          console.log(`For Realm Schema ${schema.name} there are ${schemaObjects.length} objects`)
        })

The code for Legacy Realm isn’t fully compatible with MongoDB Realm, a few things differ: have you tried without specifying the path parameter for the realm config? There’s some logic behind the location of the realm file in a synched configuration, so that may be interfering. I don’t have any problem with newer versions of Node (for reference, I’m testing with our sample repository), so I don’t think the problem is there.

The same exact configuration works with NodeJS LTS 14.16.0 but does not work with the 16.12.0 or 17.0.1, I cleared the local realm files, deleted the node_modules folder and installed every dependency again.

  • Which OS are you running it on?
  • Does it work by removing the path parameter from the configuration structure?

Had exactly the same issue on macos Monterey.
Used nvm to switch to node 15 and it works fine.

Had the same issue on node/14.19.0. Downgraded to node/14.15.4 and it worked.