不支持 crypto.getRandomValues()

jsn*_*d00 8 react-native expo react-native-webview

react-native-webview@9.0.1当我尝试使用 npm生成 QR 码时,出现此错误react-native-qrcode-generator

我正在将 react-native 与 expo 管理的工作流程一起使用。问题是它适用于 iOS,而我只在 Android 上收到错误

我自己搜索了解决方案,并尝试安装,react-native-get-random-values但这也不起作用。

有什么想法吗?

Edi*_*Edi 29

安装react-native-get-random-values 在uuid之前导入:

import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
Run Code Online (Sandbox Code Playgroud)


Jat*_*hir 6

  1. 使用此命令安装react-native-get-random-values -
    npm install react-native-get-random-values
    
    Run Code Online (Sandbox Code Playgroud)
  2. 像这样在 uuid 之前导入react-native-get-random-values -
    import "react-native-get-random-values";
    import { v4 as uuidv4 } from "uuid";
    
    Run Code Online (Sandbox Code Playgroud)

这对我有用。我希望它也对你有用。


小智 5

我刚刚在android上遇到了同样的问题。在 iOS 上运行良好。

我用以下方法解决了它:

  1. 卸载现有的 npm uninstall react-native-webview
  2. 使用expo install react-native-webview来代替。


Hus*_*soM 5

这对我有用

  1. 安装react-native-get-random-values

    npm install --save react-native-get-random-values
    
    Run Code Online (Sandbox Code Playgroud)
  2. 在 webview 导入之前导入react-native-get-random-values(非常重要

    import 'react-native-get-random-values';
    import {WebView} from 'react-native-webview';
    
    Run Code Online (Sandbox Code Playgroud)

欲了解更多信息,请阅读本期