【问题标题】:Possible Unhandled Promise Rejection (id: 20): TypeError: _util.base64.tI is not a function. React Native可能的未处理承诺拒绝(id:20):TypeError:_util.base64.tI 不是函数。反应原生
【发布时间】:2020-10-09 16:03:44
【问题描述】:

我正在使用 react native 构建一个应用程序,我使用 firebase 作为我的数据库。一切正常。我开始通过 Xcode 在我的设备上运行该应用程序。它有效,但现在我在我的设备和模拟器上收到此警告,阻止我从 firebase 数据库获取数据。警告是

“可能的未处理承诺拒绝(id:20): 类型错误:_util.base64.tI 不是函数。 (在 '_util.base64.tI(t, !1)' 中,'_util.base64.tI' 未定义)"

我不知道这个 (_util.base64) 是从哪里来的。我猜这个问题与这个代码部分(承诺)有关,因为当我删除这部分时它工作正常但没有它就无法获取数据。谁能帮忙?

useEffect(() => {
    db.collection("Appointments")
      .orderBy("Timing", "desc")
      .limit(2)
      .get()
      .then((querySnapshot) => {
        const list = [];
        querySnapshot.forEach((doc) => {
          const { Speciality, Date, TimeSlot } = doc.data();
          list.push({
            id: doc.id,
            Speciality,
            Date,
            TimeSlot,
          });
        });

        setAppointments(list);
      })
      .catch((error) => {
        alert(error.message);
        console.log(error);
      });
  }, []);

This is the warning that shows up

Those are my dependencies

【问题讨论】:

    标签: javascript xcode firebase react-native es6-promise


    【解决方案1】:

    我解决它的方法是:

    运行expo install firebase

    创建一个 config.js 文件,我将在其中放置 Firebase 凭据:

    import * as firebase from 'firebase';
    
    // Initialize Firebase
    var firebaseConfig = {
      //Your Firebase credentials
    };
    
    var app = firebase.initializeApp(firebaseConfig);
    
    export const db = app;
    

    然后在我需要的地方导入该文件

    import { db } from '../config';
    //Here's where I call firestore (You can also do this in the config file)
    import 'firebase/firestore';
    
    db.firestore().
    collection('your_collection').get().then(
        //The stuff you want to do
    );
    

    至少,现在它对我有用。

    在这个 link 中,您可以看到带有 firebase 文档的官方博览会

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-19
      • 1970-01-01
      • 1970-01-01
      • 2019-10-06
      • 2023-01-04
      • 2016-11-24
      • 2017-08-20
      • 1970-01-01
      相关资源
      最近更新 更多