realm-js: Enabling React Native Debug mode causes Error: Must first create RPC session with a valid host from rpc.js:314
Goals
Enable React Native Debug mode in order to troubleshoot console errors, set breakpoints, profile app, and monitor network requests.
Expected Results
Mobile app connects to React Native Debugger successfully and I’m able to set breakpoints, profile app, and monitor network requests, view console errors
Actual Results
- Mobile App crashes with the following error
Error: Must first create RPC session with a valid host from rpc.js:314
:19
Mobile App
Sentry Stacktrace
Error: Must first create RPC session with a valid host
File "app:///rpc.js", col 18, in sendRequest
File "app:///rpc.js", col 41, in setTimeout$argument_0
File "app:///JSTimers.js", col 17, in _allocateCallback$argument_0
File "app:///JSTimers.js", col 6, in _callTimer
File "app:///JSTimers.js", col 6, in callTimers
at <unknown>(app:///RNDebuggerWorker.js:2:134503)
React Native Debugger console
Steps to Reproduce
- Run
yarn android
to build react native application and install on device - Shake device to reveal developer menu and select
Debug
. This is successful if the user is not logged in
- Login to account which causes realm database to be initialized
- An exception occurs on mobile app

The crash occurs when the following is called **`Realm.schemaVersion(Realm.defaultPath)`** **`Realm.defaultPath`** displays an error when inspected using React Native debugger. See video below```
## Code Sample
<!---
Please provide a code sample or test case that highlights the issue.
If relevant, include your model definitions.
For larger code samples, links to external gists/repositories are preferred.
Full projects that we can compile and run ourselves are ideal!
-->
```jsx
export const runMigration = ({currentSchema}: {currentSchema: any}) => {
if (!schemas.length) {
return {schemaVersion: 0};
}
**let nextSchemaIndex = Realm.schemaVersion(Realm.defaultPath);**
schemas[schemas.length - 1].schema = currentSchema;
// If -1, it means this is a new Realm file, so no migration is needed
if (nextSchemaIndex !== -1) {
while (nextSchemaIndex < schemas.length) {
const migratedRealm = new Realm(schemas[nextSchemaIndex++]);
migratedRealm.close();
}
}
return {schemaVersion: schemas[schemas.length - 1].schemaVersion};
};
Version of Realm and Tooling
- Realm JS SDK Version: 10.0.1
- Node or React Native: 0.63.3
- Client OS & Version: OnePlus 6 A6003, Android 10
- Which debugger for React Native: React Native Debugger
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 18 (6 by maintainers)
Thank for reporting. It is a bug that we need to fix.
Started using Realm for a new project this week. Really looking forward for a fix for this one.
@kraenhansen Thanks for getting a PR out for this so quickly. However, I tried 10.0.2, the version this was fixed in, and I’m still getting this error. The stack trace in the React Native debugger appear to be the same as OP. Let me know if I can provide any more information to help debug this.
Realm: 10.0.2 React Native: 0.63.3 Android Stack Trace:
@Muzzamil75 We are working on it but I can’t say when we have a fix.
@Ninjaman494 & @jbstinson for transparency: I’m currently working on a fix for an issue related to the chrome debugger which shows itself when running an app that uses the BSON ObjectId or Decimal128 types (see #3452 and #3454 and my PR #3456 for context).
I am still getting this error even with realm 10.1.0. Anyone else? Setup react-native: 63.3 realm: 10.1.0 react native debugger 11.5 (https://github.com/jhen0409)