简体   繁体   中英

Error: Could not reach Cloud Firestore backend after changing from hardcoded data to process.env

I got this error:

@firebase/firestore: Firestore (9.9.0): Could not reach Cloud Firestore backend. Connection failed 1 times.

after chaning my firebase config from

  apiKey: "SecretApiKey",
  authDomain: "SecretAuthDomain",
  [...]
}

to:

const firebaseConfig = {
  apiKey: process.env.apiKey,
  authDomain: process.env.authDomain,
  [...]
}

also I didnt get this error like 2 days ago or when i was making other project with firebase.

I saw that problem on internet and solution was to change to this:

const firestoreDB = initializeFirestore(firebaseApp, {
  experimentalForceLongPolling: true, // this line
  useFetchStreams: false, // and this line
})

but this doesnt work also for me and i get another error.

The error message you encountered usually appears when there is no connection from your device to your database, Possibly due to network issues on your end. It also means that there is something that is not allowing the Client application to reach the Firestore backend. Try to execute it under different Networks and using different Devices.

These Github Issue1 and Stackoverflow Links2 & 3 specify custom configurations for your Cloud Firestore instance and additional checks at Client network which could possibly help to avoid such issues. I would suggest you check with these links 1 , 2 & 3 as there are alternate solutions available.

I had credentials setup in.env file which did show up as appropriate variables. However, What worked for me was putting the credentials in a .js file and use them from there. Also, please do not forget to add the credentials file in .gitignore

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM