question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native: crypto.getRandomValues() is not available when debugging with Chrome

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Reactions:28
  • Comments:45 (17 by maintainers)

github_iconTop GitHub Comments

101reactions
joebernardcommented, Jun 29, 2020

@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.

15reactions
joebernardcommented, Apr 7, 2020

I think I fixed it in my project. I upgraded React Native from 0.61.5 to the latest version 0.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

react native - crypto.getRandomValues() not supported
I'm getting this error with npm react-native-webview@9.0.1 when I try to generate a QR code with react-native-qrcode-generator.
Read more >
How to replace Math.random with crypto in JavaScript
A drop-in replacement for Math.random that generates cryptographically strong random values.
Read more >
Firebase JavaScript SDK Release Notes - Google
The SDK no longer causes React Native to log a warning about deprecation of ... getStream() is only available for Node.js and getBlob()...
Read more >
Famous Crypto Getrandomvalues Not Supported 2022 ...
React Native で UUID を使うためには?! ジェイス ブログ ... Crypto.getrandomvalues() is not available when debugging with chrome apr 9, 2020.
Read more >
Using JavaScript to Create and Generate UUIDs - HackerNoon
JS versions before 19.0 , or have to support old browsers. crypto.getRandomValues() is supported as far back as Chrome 11.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found