ReferenceError: Can't find variable: crypto

ReferenceError: Can't find variable: crypto

我正在尝试将 firebase 与 React-Native 连接 project.Config firebase 的文件是

firebase.js

import * as firebase from "firebase/app";
import "firebase/firestore";

const config = {
    apiKey: "A***********************0",
    authDomain: "gu***********************m",
    databaseURL: "ht*******************m",
    projectId: "g*****2",
    storageBucket: "g********om",
    messagingSenderId: "########",
    appId: "####################",
    measurementId: "****************"

};


firebase.initializeApp(config);
export const db = firebase.firestore();

Home.js

import { db } from '../config/firebase';


export default function Home() {

    var temp = {
        fruit: "apple",
        name: "banana"
    };
    db.collection('books').add(temp);
    console.log("after adding to db");
    var db1 = db.collection('books').get(temp);
    console.log("hello dude");
    console.log(db1);
    console.log("bye dude");

}

我在android中烧录应用程序后,出现红屏错误:

ReferenceError Can't find variable: crypto

This error is located at:
    in Home (at App.js:7)
    in gullak (at renderApplication.js:45)
    in RCTView (at AppContainer.js:109)
    in RCTView (at AppContainer.js:135)
    in AppContainer (at renderApplication.js:39)

我无法添加到 firestore 数据库中。我在这里缺少什么吗?请提前帮忙me.Thanks

好吧,问题是您正在为 node.js 使用 firebase。 Crypto 包是 nodejs 环境的一部分,但您不能在 React Native 应用程序中使用它。

要在 React Native 中使用 firebase,请查看此包 react-native-firebase