Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred

Error: A network error (such as timeout, interrupted connection or unreachable host) has occurred

我正在使用 expo 管理的工作流程,当我尝试使用 Firebase 模拟器套件时,我总是会收到此 Firebase 错误。我已经尝试了几件事,但我无法将我的项目(我使用 Android 模拟器)连接到模拟器套件。

这是我的 firebase 实例;

    import firebase from "firebase/app";
    import "firebase/firestore";
    import "firebase/auth";
    
    const firebaseConfig = {
      apiKey: "",
      authDomain: "",
      projectId: "",
      storageBucket: "",
      messagingSenderId: "",
      appId: "",
      measurementId: "",
    };
    
    !firebase.apps.length ? firebase.initializeApp(firebaseConfig) : firebase.app();
    
    export const db = firebase.firestore();
    export const auth = firebase.auth();
    
    if (__DEV__) {
      db.settings({
        host: "localhost",
        ssl: false,
      });
      auth.useEmulator("http://localhost:9099");
    }
    
    export default firebase;

这是认证部分

        import { auth, db } from "./firebase";
    
    const regUsers = async (userCred) => {
      try {
        const user = await auth.createUserWithEmailAndPassword(
          userCred.email,
          userCred.password
        );
    
        if (user) {
          const currentUser = auth.currentUser.uid;
          try {
            await db.collection("users").doc(currentUser).set({
              name: userCred.name,
              email: userCred.email,
              matricNumber: userCred.matricNumber,
              dateCreated: new Date(),
            });
          } catch (error) {
            console.log(
              "Something went wrong while saving user credentials",
              error
            );
          }
          return user;
        }
      } catch (error) {
        console.log("Something went wrong while registering user", error);
      }
    };
    
    const loginUser = async (userCred) => {
      try {
        const result = await auth.signInWithEmailAndPassword(
          userCred.email,
          userCred.password
        );
        if (result) {
          const currentUser = auth.currentUser.uid;
          return currentUser;
        }
      } catch (error) {
        console.log("Something went wrong while login user", error);
      }
    };
    
    export default {
      regUsers,
      loginUser,
    };

每当我尝试登录或注册用户时,我都会收到该错误消息。请问有谁知道我还能尝试什么。只有当我尝试连接到模拟器时才会出现错误,而我所在的互联网连接很糟糕。 我还在我的 firestore 调试日志中注意到了这个警告。 “io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead 信息:检测到 non-HTTP/2 个连接。

显然,当您使用模拟器时,您应该将 localhost 替换为 10.0.2.2:8080,它应该可以正常工作。