本文介绍了类型错误undefined不是对象(评估'Wu.getRandomValues')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我实现的用于向集合中添加数据的代码:

This is the code I implemented for adding data to collection:

import FirebaseKeys from "./config";
import firebase from "firebase";
import "@firebase/firestore";

class Fire {
  constructor() {
    firebase.initializeApp(FirebaseKeys);
  }
  addPost = async ({ text, localUri }) => {
    const remoteUri = await this.uploadPhotoAsync(localUri);
    const desc = text;

    return new Promise((res, rej) => {
      // console.log("THIS FIRESTORE" + this.firestore);
      const dbh = firebase.firestore();

      // this.firestore.collection("posts").add({
      //     text: desc,
      //     uid: this.uid,
      //     timestamp: this.timestamp,
      //     image: remoteUri
      //   })

      dbh
        .collection("posts")
        .doc("feed")
        .set({
          text: desc,
          uid: this.uid,
          timestamp: this.timestamp,
          image: remoteUri
        })
        .then(ref => {
          res(ref);
          console.log("EVERYTHING IS FINE HERE");
        })
        .catch(error => {
          console.log("ERROR HERE TOO");

          rej(error);
        });
    });
  };

  uploadPhotoAsync = async uri => {
    console.log(this);

    const path = "Date.jpg";
    return new Promise(async (res, rej) => {
      const response = await fetch(uri);
      const file = await response.blob();

      let upload = firebase
        .storage()
        .ref(path)
        .put(file);
      upload.on(
        "state_changed",
        snapshot => {},
        err => {
          console.log("ERROR IN PHOTO UPLOAD");

          rej(err);
        },
        async () => {
          const url = await upload.snapshot.ref.getDownloadURL();
          res(url);
          console.log("IMAGE IS UPLOADING FINE");
        }
      );
    });
  };
  get firestore() {
    return firebase.firestore();
  }

  get uid() {
    return (firebase.auth().currentUser || {}).uid;
  }

  get timestamp() {
    return Date.now();
  }
}

Fire.shared = new Fire();
export default Fire;

我正在使用expo react native并使用Firebase进行数据操作来构建应用程序.但是,当使用向集合中添加数据的功能时,它会显示类似

I'm building an app using expo react native and using firebase for data manipulation.But while using function for adding data to collection, it shows error like

帮帮我

错误的画面

推荐答案

更新:问题已得到解决此处,应在v7.13.3中修复.我之前曾说过降级到Firebase v7.9.0可以解决此问题.我发现该问题直到v7.13.2才存在.因此,我们可以降级到v7.13.1.但是,我们必须完全卸载firebase才能正常工作.

Update: the problem is being addressed here and should be fixed in v7.13.3. I previously stated that downgrading to firebase v7.9.0 fixed the issue. I discovered that the issue does not exist until v7.13.2. So we can downgrade to v7.13.1. However, we must completely uninstall firebase for this to work.

我在expo和firebase上遇到了相同的错误.我使用的是Expo 37版.要解决此问题,我必须在应用程序目录中使用以下命令来降级Firebase:

I experienced the same error with expo and firebase. I am using Expo version 37. To fix the problem I had to downgrade firebase using the following commands in my app's directory:

npm remove --save firebase
npm install --save [email protected]

如果我使用Firebase版本7.13.2,则会出现此错误:

If I use firebase version 7.13.2 I get this error:

这篇关于类型错误undefined不是对象(评估'Wu.getRandomValues')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 01:28