31

I'm getting this error with npm [email protected] when I try to generate a QR code with react-native-qrcode-generator

I'm using react-native with an expo managed workflow. And the thing is it works on iOS, and i only get the error on Android

I searched for a solution myself and I tried installing react-native-get-random-values but that also didn't work.

Any thoughts?

2
  • Which Expo SDK are you using? Which version of react-native-qrcode-generator? Commented Apr 12, 2020 at 10:31
  • expo@~37.0.3 and [email protected]
    – jsnid00
    Commented Apr 12, 2020 at 12:31

8 Answers 8

35

Install react-native-get-random-values Import it before uuid:

import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
0
8

I just had the same issue on android. Works fine on iOS.

I solved it with:

  1. Uninstall the existing one npm uninstall react-native-webview
  2. Use expo install react-native-webview instead.
2
  • In my case only expo install react-native-webview was enough, no need to uninstall npm package. Commented Apr 13, 2020 at 17:47
  • Need to run pod install in ios directory
    – Musthafa
    Commented Jun 14, 2023 at 10:44
8
  1. Install react-native-get-random-values using this command-
    npm install react-native-get-random-values
    
  2. Import react-native-get-random-values before uuid like this-
    import "react-native-get-random-values";
    import { v4 as uuidv4 } from "uuid";
    

It worked for me. I hope it will work for you as well.

1
  • how to get random numbers between 1 to 10 using this library?
    – Annie Tan
    Commented Nov 16, 2023 at 9:13
7

Here is what worked for me

  1. Install react-native-get-random-values

    npm install --save react-native-get-random-values
    
  2. Import react-native-get-random-values before webview import (VERY IMPORTANT)

    import 'react-native-get-random-values';
    import {WebView} from 'react-native-webview';
    

For more information, please read this issue.

2

I spent 2 days to solve the issue, I have inlineRequires: false, in metro config and changing it breaks the app.

I installed yarn add react-native-get-random-values.

Then imported react-native-get-random-values before crypto-js but it didn't work.

After hours of debugging, I found it's Babel's compiling order issue. crypto-js is always compiled earlier than react-native-get-random-values. In another word crypto-js looks for global.crypto before react-native-get-random-values assigns it. imports compile with higher priority than the rest of codes.

My file was:

import 'react-native-get-random-values'
import crypto from 'crypto-js`

The fix was lowering the compile order of crypto-js to make sure it compiles after global.crypto is assigned:

import 'react-native-get-random-values'
const crypto = require('crypto-js')
1

I made a snack with Expo SDK 37 and the exact versions you mention:

{
  "dependencies": {
    "react-native-webview": "9.0.1",
    "react-native-qrcode-generator": "1.2.1"
  }
}

It works just fine on my Android phone. The issue must be somewhere else in your implementation.

If you've changed versions recently, try to delete your node_modules and install packages again. Double-check my example and let me know if you do something different?

2
  • 1
    Thanks, i checked the snack and it worked and then updated to [email protected] and it also worked so it must have been some other dependancy So the moral here is that it wasn't an issue with react-native-webview
    – jsnid00
    Commented Apr 13, 2020 at 5:26
  • @jsnid00 I replied quicker. I double-checked with you the versions of the libraries. I created a snack to double-check and proof that it works. My answer was correct. I spent a lot of effort to help and I'm quite disappointed that you actually marked the other answer as "accepted", but not mine :( I don't think that's fair. Commented Apr 14, 2020 at 16:34
0

Try to use : npm install --save react-native-webview
It's works for me.

0

They fixed it in the webview tag 9.2.2, as shown in the changelog https://github.com/react-native-community/react-native-webview/releases/tag/v9.2.2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.