React Native (iOS) & Realm: [Error: Exception in HostFunction: unordered_map::at: key not found]
Description:
I'm studying a React Native course, and the module uses Realm for data storage.
When I call realm.write
and realm.generate
, it works fine on Android, but it throws the following error on iOS:
[Error: Exception in HostFunction: unordered_map::at: key not found]
Operating System and libraries:
- macOS Ventura 13.4, Apple M1
- XCode 14.3 (14E222b)
- iPhone 12, iOS 16.4 (tried both Apple and Rosetta mode)
- "react-native-get-random-values": "^1.9.0",
- "expo": "~48.0.15",
Code:
function handleDepartureRegister() {
try {
// omitted for brevity
realm.write(() => {
realm.create('Historic', Historic.generate({
user_id: user!.id,
license_plate: licensePlate.toUpperCase(),
description,
}))
});
Alert.alert('Saída', 'Saída do veículo registrada com sucesso.');
goBack();
} catch (error) {
console.log(error);
Alert.alert(
'Erro',
'Não foi possível registrar a saída do veículo.'
);
// omitted for brevity
}
}
Full code:
https://github.com/ceduardogodoi/ignitefleet/blob/main/src/screens/Departure/index.tsx#L54
Expected Behavior:
It should not throw any error since it works on Android.
Actual Behavior:
It threw an error on iOS.
Any help or guidance would be greatly appreciated. I appreciate any help you can provide.
What I've tried:
- Run
pod install
on the ios folder - Delete and create the simulator again
- Tried to run the simulator on both Apple and Rosetta mode
- Re-installing the expo-crypto library (and running
pod install
again)
Steps:
react-native-get-random-values
frompackage.json
package-lock.json
node_modules
npm i
to install the dependenciesnpm i [email protected]