React Native: crypto.getRandomValues() is not available when debugging with Chrome
See original GitHub issueDescribe the bug
My React Native project has been using uuid for a while with no problem. I upgraded to v7 and installed react-native-get-random-values
. I added import 'react-native-get-random-values';
and changed my uuid import to import {v4 as uuidv4} from 'uuid';
I cleaned the build in Xcode, deleted derived data, cleared watchman and metro cache, reinstalled all node modules, and ran pod install.
I still get this error:
Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported
I also tried moving the react-native-get-random-values
import to my index.js per this comment but then got this error:
Invariant Violation: Calling synchronous methods on native modules is not supported in Chrome.
Consider providing alternative methods to expose this method in debug mode, e.g. by exposing constants ahead-of-time.
To Reproduce
I followed instructions in the readme.
Expected behavior
Generate uuid.
Runtime
React Native
"react-native": "0.61.5",
"react-native-get-random-values": "^1.3.1",
"uuid": "^7.0.3"
Issue Analytics
- State:
- Created 3 years ago
- Reactions:28
- Comments:45 (17 by maintainers)
Top GitHub Comments
@ctavan @Slapbox I was missing
import 'react-native-get-random-values';
in index.js. It works now, thanks for the help. I will close this issue.I think I fixed it in my project. I upgraded React Native from
0.61.5
to the latest version0.62.1
and the error went away. I’m not set up for Android development so that may have to be tested separately but my immediate issue is solved.