crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supporte
See original GitHub issueJust got this surprising error after using uuid for so long
Environment
"react-native": "0.63.2"
"react-native-get-random-values": "^1.4.0"
"uuid": "^8.3.0"
What was tried
I get this error when const id = uuidv4()
runs. I added “react-native-get-random-values” as suggested, but with yarn and imported it this way;
import React, {useState} from 'react';
import 'react-native-get-random-values';
import {v4 as uuidv4} from 'uuid';
import RNPickerSelect from 'react-native-picker-select';
I am still getting the same error. Have to figure out other ways to generate a random ID then.
[Clear, concise description of the problem]
How to reproduce
- Install the uuid and react-native-get-random-values
- try running a component with this
const id = uuidv4()
Expected behavior
Should generate random ids
Runtime
- OS: macOS
- Runtime: react-native
- Runtime Version: 0.63.2
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:23 (12 by maintainers)
Top Results From Across the Web
1 Answer - 1 - Stack Overflow
"getRandomValues() not supported". This error occurs in environments where the standard crypto.getRandomValues() API is not supported.
Read more >Issue with UUIDv4 : r/reactnative - Reddit
My assumption is package updates since the video was uploaded in February. The error I'm getting: Error: crypto.getRandomValues() not supported.
Read more >react-native-get-random-values - npm
A small implementation of `crypto.getRandomValues` for React Native. This is useful to polyfill for libraries like ...
Read more >Crypto.getRandomValues() - Web APIs | MDN
getRandomValues() method lets you get cryptographically strong random values. The array given as the parameter is filled with random numbers ( ...
Read more >crypto.getRandomValues() | Can I use... Support tables for ...
getRandomValues(). - REC. Method of generating cryptographically random values. Usage % of. all users ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think the most important line in your last comment is “
react-native-get-random-values
must be imported before uuid is imported (or, in the case of your app, before App.js)”. The documentation as it is right now is not very clear on that, especially, the part that says…“getRandomValues() not supported” This error occurs in environments where the standard crypto.getRandomValues() API is not supported. This issue can be resolved by adding an appropriate polyfill:
React Native
react-native-get-random-values
uuid
:import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
Cursory reading of that makes one think that will work in the component where
uuid
will be used, but it doesn’t. More clarity on where, and in what order would help, eg specifically stating this has to be done inindex.js
and it has to be imported beforeApp.js
. Also highlighting the fact that in fixing this issue through importingreact-native-get-random-values
inindex.js
, it needs to be imported before theApp.js
component might help. In your example, you might also want to add a comment to reflect that specific situation. I know it is on the main page, but someone looking for a quick fix might miss that specific requirement. I have submitted an issue to that particular page in your example repo.I have implemented a polyfill for
randomUUID()
Node.js and upcoming WICG standard at https://github.com/uuidjs/randomUUID 😃