Expo app crashes when attempting to write a new record with Realm SDK

I created an Expo React Native app using the “Quick start with Expo” documentation. I modified the schema and variable names to match my data structure and set up the backend in App Services, also by following the Realm documentation. I set up Flexible device sync as well as the user authentication stuff.

Everything looks good (including log ins) until I try to add a record. The app running in an Android emulator crashes when the code gets to these lines: ('Entry is the name of my schema)

realm.write(() => {
        realm.create('Entry', Entry.generate(newEntry, userId));
      });
}

I get no error messages in console nor in the Realm logs. The schema definition in the app matches that in the Realm backend.

The following is my package.json dependencies:

    "@realm/react": "^0.3.1",
    "expo": "^44.0.6",
    "expo-dev-client": "~0.8.4",
    "expo-splash-screen": "~0.14.2",
    "expo-status-bar": "~1.2.0",
    "expo-updates": "~0.11.6",
    "react": "17.0.1",
    "react-dom": "17.0.2",
    "react-native": "0.64.3",
    "react-native-get-random-values": "~1.8.0",
    "react-native-web": "0.17.1",
    "realm": "^10.19.0"

I tried upgrading the packages to the latest version with the same results:

    "@realm/react": "^0.3.2",
    "expo": "^46.0.2",
    "expo-dev-client": "~1.1.1",
    "expo-splash-screen": "~0.16.1",
    "expo-status-bar": "~1.4.0",
    "expo-updates": "~0.14.3",
    "react": "18.0.0",
    "react-dom": "18.0.0",
    "react-native": "0.69.3",
    "react-native-get-random-values": "~1.8.0",
    "react-native-web": "0.18.7",
    "realm": "^10.19.5"

I’ve tried simplifying the schema, creating a new app in the Realm backend, and furious web searches with no luck

Thank you!

Just to follow up, I created a new Realm Expo React Native app with the template and ran it without modifying. It crashes at the same point (writing a newly created record)

Hi @Nick_Martin,

Can you please set the log level to trace (Realm.App.Sync.setLogLevel(app, 'trace'))? The messages you get leading to the crash may clarify what the SDK is doing/expecting, and give hints of what may be wrong there.

1 Like

Thanks for the suggestion!

I added that line to the AppSync file like so:

import Realm from 'realm';
import { useApp, useUser } from '@realm/react';
{other imports}

export function AppSync() {
 ...
  const app = useApp();
 
  Realm.App.Sync.setLogLevel(app, 'trace');
...

I didn’t see any additional logging in the console or the Realm app logs. Did I implement this correctly? Where should I expect to see additional logging?

Just as an update, I’ve recreated the app by following the React Native tutorial. It connects to my Realm backend without crashing.

I would still like to solve the crashing issue with Expo since that’s how I’d prefer to develop the app. I’m open to suggestions

Thanks @Nick_Martin ,

If we understood correctly, then, the “regular” React Native tutorial works as expected, but the Expo variant crashes on write operations, is that the case?