簡體   English   中英

錯誤:從硬編碼數據更改為 process.env 后無法到達 Cloud Firestore 后端

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

我收到此錯誤:

@firebase/firestore:Firestore (9.9.0):無法到達 Cloud Firestore 后端。 連接失敗 1 次。

從更改我的 firebase 配置后

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

到:

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

我也沒有像 2 天前或我用 firebase 制作其他項目時那樣收到此錯誤。

我在互聯網上看到了這個問題,解決方案是改為:

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

但這對我也不起作用,我得到另一個錯誤。

當您的設備沒有連接到數據庫時,通常會出現您遇到的錯誤消息,可能是由於您端的網絡問題。 這也意味着有些東西不允許客戶端應用程序到達 Firestore 后端。 嘗試在不同的網絡下使用不同的設備執行它。

這些Github Issue1 和Stackoverflow Links2 & 3為您的 Cloud Firestore 實例指定自定義配置,並在客戶端網絡上進行額外檢查,這可能有助於避免此類問題。 我建議您檢查這些鏈接123 ,因為有可用的替代解決方案。

我在 .env 文件中設置了憑據,它確實顯示為適當的變量。 但是,對我有用的是將憑據放在.js文件中並從那里使用它們。 另外,請不要忘記在.gitignore中添加憑據文件

暫無
暫無

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

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