Firestore 未使用 Expo-dev-client 连接

muh*_*pqi 1 react-native expo google-cloud-firestore

如果我使用expo start,我的 firestore 在 Expo Go 中工作正常。但是当我使用它时expo start --dev-client它停止工作。我已经尝试使用EAS Migration Guide来使用 EAS ,但发生了同样的错误。
这是错误消息:

@firebase/firestore:, Firestore (8.2.2): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
    This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
    at node_modules/@firebase/logger/dist/index.cjs.js:98:8 in defaultLogHandler
    at node_modules/@firebase/logger/dist/index.cjs.js:212:8 in Logger.prototype.error
    at node_modules/@firebase/firestore/dist/rn/prebuilt.rn-f9cd27ba.js:60:8 in P
    at node_modules/@firebase/firestore/dist/rn/prebuilt.rn-f9cd27ba.js:8135:20 in <global>
    at node_modules/@firebase/firestore/dist/rn/prebuilt.rn-f9cd27ba.js:8105:8 in stream.onMessage$argument_0
    at node_modules/@firebase/firestore/dist/rn/prebuilt.rn-f9cd27ba.js:5218:67 in Ds#constructor
    at node_modules/@firebase/firestore/dist/rn/prebuilt.rn-f9cd27ba.js:11781:54 in <global>
    
      @firebase/firestore:, Firestore (8.2.2): Connection, WebChannel transport errored
Run Code Online (Sandbox Code Playgroud)

我的连接没有问题,因为App中的API仍然有效。
EAS 或 expo-dev-client 是否有额外的设置?

这是我如何启动我的 firebase

class FirebaseServices {
static handleFirebaseConfig() {
    var firebaseConfig = {
        apiKey: 'API_KEY',
        authDomain: "firebaseapp.com",
        projectId: "PROJECT_ID",
        storageBucket: "STORAGE",
        messagingSenderId: "ID",
        appId: "APP_ID",
        measurementId: "ID"
    };
    let app;
    if (firebase.apps.length === 0) {
        app = firebase.initializeApp(firebaseConfig)
    }
    else {
        app = firebase.app();
    }
    return app;    
}}    const db = FirebaseServices.handleFirebaseConfig().firestore()
Run Code Online (Sandbox Code Playgroud)

muh*_*pqi 5

我通过添加实验性的ForceLongPolling,使用线程中的答案解决了这个问题。

 class FirebaseServices {
static handleFirebaseConfig() {
    var firebaseConfig = {
        apiKey: 'API_KEY',
        authDomain: "firebaseapp.com",
        projectId: "PROJECT_ID",
        storageBucket: "STORAGE",
        messagingSenderId: "ID",
        appId: "APP_ID",
        measurementId: "ID"
    };
    let app;
    if (firebase.apps.length === 0) {
        app = firebase.initializeApp(firebaseConfig)
        firebase().firestore().settings({
          experimentalForceLongPolling: true, // this line
          useFetchStreams: false, // and this line
        })
    }
    else {
        app = firebase.app();
    }
    return app;    
    }
   }  
  const db = FirebaseServices.handleFirebaseConfig().firestore()
Run Code Online (Sandbox Code Playgroud)

我已经将我的 firebase 升级到 v9,所以它变成这样

    const app = initializeApp(firebaseConfig);

   const firestoreDB = initializeFirestore(app, {
     experimentalForceLongPolling: true,  
     useFetchStreams: false,  
    })
   export const dbFs = getFirestore(app);
Run Code Online (Sandbox Code Playgroud)