简体   繁体   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?

I have been developing a project in Expo, and since last week I switched to eas build from the calssic "expo build:android".我一直在 Expo 开发一个项目,从上周开始,我从经典的“expo build:android”切换到 eas build。 With that change I am getting a weird error with Firestore connection.通过这种更改,我在 Firestore 连接中遇到了一个奇怪的错误。 For testing I created a fresh project, then installed firebase with "npx expo install firebase".为了进行测试,我创建了一个新项目,然后使用“npx expo install firebase”安装了 firebase。 I Initialized firebase, then logged in with "getAuth()", which still works and tried to fetch some data from Firestore.我初始化了 firebase,然后使用“getAuth()”登录,它仍然有效,并尝试从 Firestore 获取一些数据。 I created a buttom for it, and when pressing it I got the same error.我为它创建了一个按钮,当按下它时,我得到了同样的错误。

So it seems like to me that this happens on every new project.所以在我看来,每个新项目都会发生这种情况。

Here's my package.json这是我的 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 }

Environment环境

  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 =>

Please specify your device/emulator/simulator platform, model and version请指定您的设备/模拟器/模拟器平台,model 和版本

Android Running app on sdk_gphone_x86 - Pixel_2_API_30 Android 在 sdk_gphone_x86 上运行应用程序 - Pixel_2_API_30

Error output错误 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**

Reproducible demo or steps to reproduce from a blank project可重现的演示或从空白项目重现的步骤

On Windows在 Windows

  1. Create a fresh project with "npx create-expo-app expo-firestore", then install Firebase with "npx expo install firebase", then "expo start"使用“npx create-expo-app expo-firestore”创建一个新项目,然后使用“npx expo install firebase”安装 Firebase,然后安装“expo start”
  2. Init Firebase (firebase.js)初始化 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. Log in登录
 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. Try to retrieve some data尝试检索一些数据
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")
    }
  }

Fix was:修复是:

changing:改变:

import { getFirestore } from 'firebase/firestore';

to:至:

import { initializeFirestore  } from 'firebase/firestore';



const db_firestore = initializeFirestore(firebaseApp);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter -Firebase/FireStore - 无法访问 Cloud Firestore 后端。 后端在 10 秒内没有响应 - Flutter -Firebase/FireStore - Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds 无法访问 Cloud Firestore 后端。 后端在 10 秒内没有响应 - Flutter Android Studio - Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds - Flutter Android Studio Firestore 错误:Firestore (9.1.0):无法访问 Cloud Firestore 后端 - Firestore errors: Firestore (9.1.0): Could not reach Cloud Firestore backend React Native Expo Firebase Firestore (9.9.3):无法访问 Cloud Firestore 后端 - React Native Expo Firebase Firestore (9.9.3): Could not reach Cloud Firestore backend 无法使用 Node.js 在 CloudRun 上访问 Cloud Firestore 后端 - Could not reach Cloud Firestore backend on CloudRun with Node.js 错误:从硬编码数据更改为 process.env 后无法到达 Cloud Firestore 后端 - Error: Could not reach Cloud Firestore backend after changing from hardcoded data to process.env 从firestore(firebase)获取数据时出现错误。 我正在使用本机反应 - I am getting an error while fetching data from firestore(firebase). I am using react native Cloud Functions - Cloud Firestore 错误:无法获取 serverTimestamp - Cloud Functions - Cloud Firestore error: can't get serverTimestamp 如果我的后端是 firebase firestore,我如何在我的 react js 应用程序中使用 JWT - How do i use JWT in my react js app, if my backend is firebase firestore Firestore 错误“无法反序列化对象” - Firestore Error "Could not deserialize object"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM