簡體   English   中英

為什么我收到 Expo Firestore 錯誤:無法到達 Cloud Firestore 后端。 后端沒有在 10 秒內響應?

[英]Why I am getting Expo Firestore error: Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds?

我一直在 Expo 開發一個項目,從上周開始,我從經典的“expo build:android”切換到 eas build。 通過這種更改,我在 Firestore 連接中遇到了一個奇怪的錯誤。 為了進行測試,我創建了一個新項目,然后使用“npx expo install firebase”安裝了 firebase。 我初始化了 firebase,然后使用“getAuth()”登錄,它仍然有效,並嘗試從 Firestore 獲取一些數據。 我為它創建了一個按鈕,當按下它時,我得到了同樣的錯誤。

所以在我看來,每個新項目都會發生這種情況。

這是我的 package.json

{ "name": "rn-admob-test", "version": "1.0.0", "main": "node_modules/expo/AppEntry.js", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web" }, "dependencies": { "expo": "~46.0.9", "expo-dev-client": "~1.2.1", "expo-status-bar": "~1.4.0", "firebase": "^9.9.4", "react": "18.0.0", "react-native": "0.69.5", "react-native-google-mobile-ads": "^8.0.0" }, "devDependencies": { "@babel/core": "^7.12.9" }, "private": true }

環境

  expo-env-info 1.0.5 environment info:
    System:
      OS: Windows 10 10.0.19043
    Binaries:
      Node: 16.13.1 - D:\Fos progik\NodeJS\node.EXE
      Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
      npm: 8.1.2 - D:\Fos progik\NodeJS\npm.CMD
    SDKs:
      Android SDK:
        API Levels: 28, 29, 30, 31
        Build Tools: 28.0.3, 29.0.2, 29.0.3, 30.0.2, 30.0.3, 31.0.0
        System Images: android-28 | Google APIs Intel x86 Atom_64, android-30 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: Version     2020.3.0.0 AI-203.7717.56.2031.7784292
    npmPackages:
      expo: ~46.0.9 => 46.0.10
      react: 18.0.0 => 18.0.0
      react-native: 0.69.5 =>

請指定您的設備/模擬器/模擬器平台,model 和版本

Android 在 sdk_gphone_x86 上運行應用程序 - Pixel_2_API_30

錯誤 output

**[2022-09-09T09:19:27.787Z]  @firebase/firestore:, Firestore (9.9.4): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent 
error: FirebaseError: [code=unavailable]: The service is temporarily unavailable.
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\expo\build\environment\react-native-logs.fx.js:null in error
at node_modules\@firebase\logger\dist\index.cjs.js:null in defaultLogHandler
at node_modules\@firebase\logger\dist\index.cjs.js:null in Logger.prototype.error
at node_modules\@firebase\firestore\dist\index.rn.js:null in $
at node_modules\@firebase\firestore\dist\index.rn.js:null in <global>
at node_modules\@firebase\firestore\dist\index.rn.js:null in cu#Qo
at node_modules\@firebase\firestore\dist\index.rn.js:null in Promise.all.then._catch$argument_0
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in asyncGeneratorStep
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in _next
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in Promise$argument_0
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in tryCallTwo
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in doResolve
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in Promise
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in <anonymous>
at http://192.168.0.73:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in _bu
at http://192.168.0.73:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in bu
at node_modules\@firebase\firestore\dist\index.rn.js:null in <global>
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in asyncGeneratorStep
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in _next
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in Promise$argument_0
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in tryCallTwo
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in doResolve
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in Promise
at node_modules\@babel\runtime\helpers\asyncToGenerator.js:null in <anonymous>
at http://192.168.0.73:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in close       
at node_modules\@firebase\firestore\dist\index.rn.js:null in uu#reset
at node_modules\@firebase\firestore\dist\index.rn.js:null in uu#constructor
at node_modules\@firebase\firestore\dist\index.rn.js:null in uu
at node_modules\@firebase\firestore\dist\index.rn.js:null in Va
at node_modules\@firebase\firestore\dist\index.rn.js:null in Sa#constructor
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in tryCallOne
at node_modules\react-native\node_modules\promise\setimmediate\core.js:null in setImmediate$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _allocateCallback$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callReactNativeMicrotasksPass
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __callReactNativeMicrotasks
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in flushedQueue
[Unhandled promise rejection: FirebaseError: Failed to get document because the client is offline.]
at node_modules\@babel\runtime\helpers\construct.js:null in _construct
at node_modules\@babel\runtime\helpers\wrapNativeSuper.js:null in Wrapper
at http://192.168.0.73:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in _createSuperInternal
at node_modules\@firebase\util\dist\index.esm2017.js:null in FirebaseError#constructor
at http://192.168.0.73:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&hot=false&strict=false&minify=false:null in _createSuperInternal
at node_modules\@firebase\firestore\dist\index.rn.js:null in j#constructor
at node_modules\@firebase\firestore\dist\index.rn.js:null in Jc#write
at node_modules\@firebase\firestore\dist\index.rn.js:null in qc
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _allocateCallback$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:null in callTimers
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:null in callFunctionReturnFlushedQueue**

可重現的演示或從空白項目重現的步驟

在 Windows

  1. 使用“npx create-expo-app expo-firestore”創建一個新項目,然后使用“npx expo install firebase”安裝 Firebase,然后安裝“expo start”
  2. 初始化 Firebase (firebase.js)
//Firebase
import { initializeApp } from 'firebase/app';
import { getFirestore } from 'firebase/firestore';
import { getAuth } from 'firebase/auth';

//Firebase connect
const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    appId: ""
  };

//Connecting to Firebase database
const firebaseApp = initializeApp(firebaseConfig);
const db_firestore = getFirestore(firebaseApp, {
    experimentalForceLongPolling: true
  });
const auth = getAuth(firebaseApp);

//Exporting data so I can import
export {
  auth,
  db_firestore,
};
  1. 登錄
 import {signInAnonymously} from 'firebase/auth';

  function Login(){
    signInAnonymously(auth)
    .then((result) => {
        console.log(result)
    })
    .catch((error) => {
        const errorCode = error.code;
        const errorMessage = error.message;
        console.log("Anonymus login error:", errorCode, errorMessage)
    });
  }
  1. 嘗試檢索一些數據
import { doc, getDoc} from '@firebase/firestore';

async function RetrieveData(){
    if (auth.currentUser) {
      const ref = doc(db_firestore, 'users', auth.currentUser.uid)
      const snapshot = await getDoc(ref);
      const data = snapshot.data();
      console.log(data)
    }
    else{
      return console.log("You have to log in first")
    }
  }

修復是:

改變:

import { getFirestore } from 'firebase/firestore';

至:

import { initializeFirestore  } from 'firebase/firestore';



const db_firestore = initializeFirestore(firebaseApp);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM