LinusU / react-native-get-random-values

A small implementation of `getRandomValues` for React Native
MIT License
350 stars 48 forks source link

TypeError: Cannot read property 'getRandomBase64String' of undefined, js engine: hermes #42

Closed MortadhaFadhlaoui closed 1 year ago

MortadhaFadhlaoui commented 1 year ago

Description

Running the ios build after upgrading to Expo SDK 48, we get this error:

TypeError: Cannot read property 'getRandomBase64String' of undefined, js engine: hermes

After some investigation seems like this library needs to be updated because it's using ExpoRandom after expo-random was deprecated in SDK 48

/**
 * @param {number} byteLength
 * @returns {string}
 */
function getRandomBase64 (byteLength) {
  if (NativeModules.RNGetRandomValues) {
    return NativeModules.RNGetRandomValues.getRandomBase64(byteLength)
  } else if (NativeModules.ExpoRandom) {
    // Expo SDK 41-44
    return NativeModules.ExpoRandom.getRandomBase64String(byteLength)
  } else if (global.ExpoModules) {
    // Expo SDK 45+
    return global.ExpoModules.ExpoRandom.getRandomBase64String(byteLength);
  } else {
    throw new Error('Native module not found')
  }
}

React Native Get Random Values version

1.8.0

React Native version

0.71.4

Platforms

IOS

JavaScript runtime Hermes

Workflow React Native (without Expo)

Device Simulator

Acknowledgments Yes

pvinis commented 1 year ago

dup of https://github.com/LinusU/react-native-get-random-values/issues/41