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.

crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supporte

See original GitHub issue

Just 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

  1. Install the uuid and react-native-get-random-values
  2. 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:23 (12 by maintainers)

github_iconTop GitHub Comments

29reactions
chinomnsoawaziecommented, Sep 12, 2020

As mentioned in the documentation and as shown in the working example react-native-get-random-values must be imported before uuid is imported (or, in the case of your app, before App.js is imported, just like it’s done here).

I’ve submitted a PR to your sample repo which hopefully fixes the issue chinomnsoawazie/dogstagram-frontweb-mobile#1 (I couldn’t properly test it because I couldn’t get past the login screen, I was able to produce a uuid on the login screen though using this commit: ctavan/dogstagram-frontweb-mobile@efac2b8).

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

  1. Install react-native-get-random-values
  2. Import it before 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 in index.js and it has to be imported before App.js. Also highlighting the fact that in fixing this issue through importing react-native-get-random-values in index.js, it needs to be imported before the App.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.

3reactions
pirannacommented, Mar 26, 2021

I have implemented a polyfill for randomUUID() Node.js and upcoming WICG standard at https://github.com/uuidjs/randomUUID 😃

Read more comments on GitHub >

github_iconTop 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 >

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