You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

切换EAS Build后Expo项目Cloud Firestore连接失败问题咨询

Expo切换到EAS Build后Cloud Firestore连接异常

我用Expo开发项目,上周把构建方式从传统的expo build:android改成EAS Build后,出现了Cloud Firestore连接异常的问题。为测试问题,我新建了项目,通过npx expo install 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 =>

运行设备

Android模拟器:sdk_gphone_x86 - Pixel_2_API_30

错误输出

[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环境)

  • 通过npx create-expo-app expo-firestore创建新项目,执行npx expo install firebase安装Firebase,然后运行expo start
  • 初始化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,
};
  • 实现登录功能:
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)
    });
  }
  • 尝试获取数据:
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")
    }
  }

内容的提问来源于stack exchange,提问作者AnyamBorogass

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 07:15:34