LoginSignup
9
1

More than 3 years have passed since last update.

@firebase/firestore: Firestore (8.2.9): Could not reach Cloud Firestore backend.を解消する

Posted at

先日firebaseとreactを接続するところでハマってしまったので
同じ境遇に会ったらぜひ参考にしていただきたいです!

接続がうまくいかなかった原因

結論必要な記載が漏れていた
【エラー文】

@firebase/firestore: Firestore (8.2.9): Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: FirebaseError: [code=permission-denied]: Permission denied on resource project "clone3411",.
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

最初は接続環境が悪いのかなと思い、そのような記事がたくさんあり何度もwifiをつけ外ししてたがうまくいかず。。。
エラー文をよくみるとclone3411とに接続がうまくいってないと記載があった!
firebaseconfigファイルが悪いのではと考えfirebaseの設定の箇所を再度コピーしてみた

firebase.js
  var firebaseConfig = {
    apiKey: "******",
    authDomain: "****",
    projectId: "****",
    storageBucket: "*****",
    messagingSenderId: "*****",
    appId: "****",
    measurementId: "*****"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();

そのままコピーしてるはずだからうまくいくはず。。。
まだエラー文は直らない。どうしてだろう。。。

解決方法

調べていくと今のfirebaseConfigには1行足りないコードがあります!
それはdatabaseURL:"****"です!
この記述は自分で記載する必要があり(何故なのかわかりません)それを記述することでエラー文がなくなりました!
URLを書くときは、databaseURL:"https://projectId(記載のID).firebaseio.com"を書く必要があります!

ぜひ同じような現象が起きたときはconfigファイルを見てみるといいかなと思います!

9
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
1