【问题标题】:Type Error undefined is not an object (evaluating 'Wu.getRandomValues')类型错误未定义不是对象(评估'Wu.getRandomValues')
【发布时间】:2020-04-04 13:07:10
【问题描述】:

这是我为向集合添加数据而实现的代码:

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 进行数据操作。 但是在使用向集合添加数据的功能时,它会显示如下错误

undefined 不是对象(评估 'Wu.getRandomValues')

帮帮我

SCREENSHOT OF THE ERROR

【问题讨论】:

    标签: firebase react-native google-cloud-firestore expo


    【解决方案1】:

    更新:问题正在解决here,应该在 v7.13.3 中修复。我之前说过降级到 firebase v7.9.0 解决了这个问题。我发现这个问题直到 v7.13.2 才存在。所以我们可以降级到 v7.13.1。但是,我们必须完全卸载 firebase 才能正常工作。

    我在使用 expo 和 firebase 时遇到了同样的错误。我使用的是 Expo 37。为了解决这个问题,我必须在我的应用目录中使用以下命令降级 firebase:

    npm remove --save firebase 
    npm install --save firebase@7.13.1
    

    如果我使用 Firebase 7.13.2 版,我会收到此错误:

    undefined 不是对象(评估 'Wu.getRandomValues')

    【讨论】:

    • 你用什么函数向firestore发送数据?
    【解决方案2】:

    另一个问题的评论有一个解决方案:我遇到了同样的问题。将 firebase 版本降级到 @7.12.0,它又可以工作了。

    【讨论】:

      【解决方案3】:

      这里也是同样的问题。我发现我在 android 上的 expo 客户端是由 google play 更新的。最新版本使用 expo sdk 37。 我刚刚在我的项目中运行了 expo update,一切都恢复正常了

      【讨论】:

        【解决方案4】:

        此处给出的答案(降级)有效。 但就我而言,在降级时,我发现真正的错误是权限错误(生产模式)。

        所以真正的问题是这个错误掩盖了真正的错误。希望它很快得到修复。

        【讨论】:

          猜你喜欢
          • 2020-07-16
          • 2020-04-02
          • 1970-01-01
          • 2023-03-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-22
          • 2021-10-21
          相关资源
          最近更新 更多