使用 firestore Firestore 时出现以下错误:错误:FIRESTORE (8.1.2) INTERNAL ASSERTION FAILED: Unexpected state

Posted

技术标签:

【中文标题】使用 firestore Firestore 时出现以下错误:错误:FIRESTORE (8.1.2) INTERNAL ASSERTION FAILED: Unexpected state【英文标题】:getting the following error when using firestore Firestore: Error: FIRESTORE (8.1.2) INTERNAL ASSERTION FAILED: Unexpected state 【发布时间】:2021-06-28 03:06:28 【问题描述】:

我目前正在开发一个应用程序,它工作了一段时间......当我注册时,我将用户添加到 firestore,它仍然有效,但现在每当我在其他屏幕上使用 firestore 时,它​​都会抛出以下错误:

 @firebase/firestore:, Firestore (8.1.2): FIRESTORE (8.1.2) INTERNAL ASSERTION FAILED: Unexpected state

Stack trace:
  node_modules/react-native/Libraries/LogBox/LogBox.js:148:8 in registerError
  node_modules/react-native/Libraries/LogBox/LogBox.js:59:8 in errorImpl
  node_modules/react-native/Libraries/LogBox/LogBox.js:33:4 in console.error
  node_modules/expo/build/environment/react-native-logs.fx.js:27:4 in error
  http://127.0.0.1:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:171277:27

这是出现错误的屏幕代码

import React,  Component  from 'react';
import 
  View,
  Text,
  StatusBar,
  TouchableOpacity,
  FlatList,
 from 'react-native';
import  Ionicons, FontAwesome  from '@expo/vector-icons';
import  ListItem, Avatar, Badge  from 'react-native-elements';
import firebase from 'firebase';
import theme from '../Props/theme';

export default class Home extends Component 
  constructor() 
    super();

    this.state = 
      patients: [],
    ;

    this.patient = null;
  

  componentDidMount = async () => 
    this.patient = await firebase
      .firestore()
      .collection('Patients')
      .where('doctorEmail', '==', firebase.auth().currentUser.email)
      .onSnapshot((snapshot) => 
        var docData = snapshot.docs.map((document) => document.data());
        this.setState(
          patients: docData,
        );
      );
  ;

  render() 
    return (
      <View style= flex: 1, backgroundColor: '#FFF' >
        <StatusBar hidden />
        <TouchableOpacity
          style= position: 'absolute', top: 10, right: 20 
          onPress=() => 
            this.props.navigation.push('Settings');
          >
          <Ionicons name="ios-settings-sharp" color="#02075d" size=40 />
        </TouchableOpacity>
        <FlatList
          data=this.state.patients
          style= marginTop: 50 
          renderItem=( item ) => (
            <ListItem>
              <ListItem.Content
                style=
                  backgroundColor: '#f0f0f0',
                  padding: 20,
                  borderRadius: 20,
                >
                <View style= flexDirection: 'row' >
                  <View>
                    <Avatar
                      rounded
                      icon= name: 'user', type: 'font-awesome' 
                      activeOpacity=0.7
                      source=
                        uri:
                          'https://s3.amazonaws.com/uifaces/faces/twitter/adhamdannaway/128.jpg',
                      
                    />
                    <Badge
                      status=
                        item.allVisitsCompleted === false
                          ? theme.darkPink
                          : theme.darkBlue
                      
                      containerStyle=
                        position: 'absolute',
                        top: -1,
                        right: -3,
                      
                      badgeStyle=
                        item.allVisitsCompleted === false
                          ? 
                              width: 15,
                              height: 15,
                              borderRadius: 7.5,
                              backgroundColor: theme.darkPink,
                            
                          : 
                              width: 15,
                              height: 15,
                              borderRadius: 7.5,
                              backgroundColor: theme.darkBlue,
                            
                      
                    />
                  </View>
                  <View style= flexDirection: 'column', marginLeft: 20 >
                    <ListItem.Title>item.patientName</ListItem.Title>
                    <ListItem.Subtitle>item.patientId</ListItem.Subtitle>
                  </View>

                  <TouchableOpacity
                    style= marginLeft: 185, marginTop: 5 
                    onPress=() =>
                      this.props.navigation.navigate('Edit', 
                        details: item,
                      )
                    >
                    <FontAwesome name="edit" size=24 color="black" />
                  </TouchableOpacity>
                </View>
              </ListItem.Content>
            </ListItem>
          )
          keyExtractor=(item, index) => index.toString()
        />
      </View>
    );
  

我个人认为这个错误是由于获取函数(onSnapshot 或 .get 函数)引起的...如果您知道如何解决此问题,请告诉我...提前致谢!

【问题讨论】:

【参考方案1】:

我现在解决了这个问题...如果有人遇到这个问题...执行以下步骤:

在项目的根目录中运行 expo install firebase 如果仍然无法正常工作,请在出现上述错误的所有屏幕中导入您的配置文件(如果有)

【讨论】:

以上是关于使用 firestore Firestore 时出现以下错误:错误:FIRESTORE (8.1.2) INTERNAL ASSERTION FAILED: Unexpected state的主要内容,如果未能解决你的问题,请参考以下文章

检索数据时出现 Vue/Firestore/Firebase 错误

使用 Firestore 获取数据时出现颤振错误

尝试搜索 Firestore 并重新加载 tableview 时出现 SearchBar 问题

合并 Firestore 查询时出现重复数据

使用 firebaseui:firebase-ui-firestore 构建发布 APK 时出现问题

添加“cloud_firestore”时出现颤振错误