Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expo: Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unknown]: undefined undefined: undefined #8761

Open
cristianbogdan opened this issue Feb 5, 2025 · 9 comments

Comments

@cristianbogdan
Copy link

cristianbogdan commented Feb 5, 2025

Operating System

macOS, several versions

Environment (if applicable)

Chrome 130-132

Firebase SDK Version

11.0.2 but tested also with 11.2 and several 9 versions

Firebase SDK Product(s)

Firestore

Project Tooling

Expo go app with metro bundler (node), React Native

Detailed Problem Description

I have a firestore getDoc() in the startup (bootstrap) code of an Expo Go (React Native) app. On startup, when the app is accessed from the browser (localhost:8081), I see the following output.

λ Bundled 2186ms node_modules/expo-router/node/render.js (809 modules)
Web Bundled 2446ms node_modules/expo-router/entry.js (618 modules)
[2025-02-05T08:42:51.037Z]  @firebase/firestore: Firestore (11.0.2): GrpcConnection RPC 'Listen' stream 0x1dbcf358 error. Code: undefined Message: undefined undefined: undefined
[2025-02-05T08:42:51.038Z]  @firebase/firestore: Firestore (11.0.2): GRPC error has no .code
[2025-02-05T08:42:51.039Z]  @firebase/firestore: Firestore (11.0.2): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unknown]: undefined undefined: undefined
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.
/path/to/project/node_modules/@expo/cli/build/src/utils/errors.js:123
    throw error;
    ^

[FirebaseError: Failed to get document because the client is offline.] {
  code: 'unavailable',
  customData: undefined,
  toString: [Function (anonymous)]
}

Node.js v20.8.0

Without a catch() to the getDoc() the whole expo server stops since initial JS code throws. With a catch, Expo seems to execute again the bootstrap sequence and on the 2nd attempt to getDoc() (about one second later) resolves correctly and the app works.

Steps and code to reproduce issue

package.json


{
  "version": "1.0.0",
  "scripts": {
    "dev": "expo start"
  },
  "dependencies": {
    "babel-plugin-module-resolver": "^5.0.2",
    "expo": "~52.0.9",
    "expo-router": "~4.0.7",
    "firebase": "^11.0.2",
    "react-native-web": "^0.19.13"
  },
  "private": true,
  "devDependencies": {
    "typescript": "^5.3.3"
  }
}

src/app/index.js

import { initializeApp } from "firebase/app";
import {firebaseConfig} from "src/firebaseConfig.js";
const app= initializeApp(firebaseConfig);

import {getFirestore, doc, getDoc} from "firebase/firestore";
const db= getFirestore(app);

getDoc(doc(db, "someCollection", "1")).then(console.log)

I tested on 3 different machines (all Mac), with a number of Firebase versions, from 9 to the latest 11.2.

@cristianbogdan cristianbogdan added new A new issue that hasn't be categoirzed as question, bug or feature request question labels Feb 5, 2025
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@jbalidiong jbalidiong added api: firestore needs-attention and removed needs-triage new A new issue that hasn't be categoirzed as question, bug or feature request labels Feb 5, 2025
@cristianbogdan
Copy link
Author

For whatever it's worth, i added above minimal configuration to reproduce

@P10Designs
Copy link

Same issue here, just on android

@milaGGL
Copy link
Contributor

milaGGL commented Feb 13, 2025

Hi @cristianbogdan, thank you for raising this issue. I am not very familiar with Expo Go, could you please provide a minimal reproduction app?

Besides, could you please enable "debug" level logging, and check the logs? Have catch() block captured any errors?

@P10Designs
Copy link

P10Designs commented Feb 14, 2025

Here there´s a gist with my logs in debug mode

LOGS

I´m using ionic with React and capacitor.

I have this issue just with Android devices (emulated or fisical), with Ios it´s working perfectly

import { initializeApp } from "firebase/app";
import { initializeFirestore, setLogLevel } from "firebase/firestore";
import { getAnalytics } from "firebase/analytics";

import firebaseConfig from "./config";

const app = initializeApp(firebaseConfig);
const db = initializeFirestore(app, {
  experimentalForceLongPolling: true
});
setLogLevel("debug");

const analytics = getAnalytics(app);

export { db, app, analytics };

This is the code i have running the connection with firebase. I saw in other post a similar issue and tryed solving it with experimentalForceLongPolling: true but without a any result

I´ve tryed diferent versions of firebase but i´m currently using "firebase": "11.3.1"

@hsubox76
Copy link
Contributor

React Native and Ionic are really different environments so these are probably two separate issues and should be tracked accordingly.

For the first React Native issue, what is the target user environment? Is it web? From the reference to localhost I assume it's web. If so, it's grabbing the wrong bundle as only the Node Firestore bundle uses grpc (it doesn't work in web). Is there some way you can reconfigure your metro bundler to prefer "browser" or "module" fields (or if it's resolving with ESM, the "import" or "browser" fields)? Although I do see that the file is expo-router/node/render.js so is it meant to be running a Node process? Which step of the process is this? I wasn't familiar with a Node process in Expo.

The second issue with Ionic seems to be a different issue as I see from the logs it's using Webchannel and not grpc - I would suggest starting a new issue and providing any additional details you can.

@milaGGL
Copy link
Contributor

milaGGL commented Feb 14, 2025

I´m using ionic with React and capacitor.

@P10Designs, I wonder if you are running into the same problem as this ticket, since you are using capacitor as well: #8255 (comment)

@cristianbogdan
Copy link
Author

cristianbogdan commented Feb 19, 2025

@hsubox76

For the first React Native issue, what is the target user environment? Is it web? From the reference to localhost I assume it's web.

I start npm run dev and that defaults to web but I guess this issue will occur on any target

If so, it's grabbing the wrong bundle as only the Node Firestore bundle uses grpc (it doesn't work in web).

When accessing localhost:8081 Expo seems to execute src/app/index.js in node (in the terminal) initially, but then after loading a few more bundles, the very same code executes in the browser. The firestore part of the index.js probably fails in node but succeeds in the browser. This also explains why firestore initialization from a React component lifecycle like useEffect(initializeFirestore, []) works with no error, as the lifecycle will only be triggered in the browser.

This is the log of a more complex application (with routing etc). Custom printouts are mine. I print once at the application start, and also when catching in the getDoc() promise chain. As you can see, a few more bundles are loaded after the firestore initialization fails.

Logs for your project will appear below. Press Ctrl+C to exit.
λ Bundled 1772ms node_modules/expo-router/node/render.js (841 modules)
λ  LOG  Custom console.log: application starts!
Web node_modules/expo-router/entry.js ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓░ 95.0% (737/756)λ  WARN  "shadow*" style props are deprecated. Use "boxShadow". 
λ  WARN  props.pointerEvents is deprecated. Use style.pointerEvents 
[2025-02-19T23:46:28.339Z]  @firebase/firestore: Firestore (11.2.0): GrpcConnection RPC 'Listen' stream 0x6f8aea8a error. Code: undefined Message: undefined undefined: undefined
[2025-02-19T23:46:28.340Z]  @firebase/firestore: Firestore (11.2.0): GRPC error has no .code
[2025-02-19T23:46:28.341Z]  @firebase/firestore: Firestore (11.2.0): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=unknown]: undefined undefined: undefined
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.
Custom console.error: catch() caught the getDoc error [FirebaseError: Failed to get document because the client is offline.] {
  code: 'unavailable',
  customData: undefined,
  toString: [Function (anonymous)]
}
Web Bundled 3399ms node_modules/expo-router/entry.js (756 modules)
Web Bundled 485ms node_modules/expo-router/entry.js (764 modules)
 LOG  [web] Logs will appear in the browser console

The log line Custom console.log: application starts! is then visible in the browser console, so index.js (or _layout.js) is executed in the browser as well. After that, the firestore initialization runs again, this time in the browser, and succeeds.

@cristianbogdan
Copy link
Author

cristianbogdan commented Mar 2, 2025

Minimal stackblitz that reproduces the issue. When loading the Stackblitz,

  • the project installs (npm install)
  • Expo runs (npm run dev)
  • Logs for your project will appear below. Press Ctrl+C to exit. is displayed,
  • a pretty long pause follows
  • but eventually a http access is made to the development server
  • so the bundling starts for node_modules/expo-router/entry.js and node_modules/expo-router/node/render.js
  • then the Firebase error occurs and npm run dev (Expo) terminates.

You can remove "output":"static" from app.json and run npm run dev again. Then everything works, probably because only one bundle is made (node_modules/expo-router/node/entry.js)

Alternatively, catching in the getDoc promise chain in src/app/index.js also enables Expo to work without terminating prematurely. The error caught is the same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants