簡體   English   中英

努力重新獲得基礎以識別我初始化的 firebase DB

[英]Struggling to get re-base to recognise my initialized firebase DB

我正在研究一些 ReactJS 教程,我之前已經看過它們,但我有一點更新,因為我已經有一段時間沒有理由使用 ReactJS 了。 自從我上次查看以來,firebase / rebase 發生了一些變化,並且示例代碼無法完成我需要它做的工作。

這是使用firebase兼容版本的代碼

import Rebase from 're-base';
import firebase from 'firebase/compat/app';
import 'firebase/compat/database';

const firebaseApp = firebase.initializeApp({
  apiKey: "xxx",
  authDomain: "xxx.firebaseapp.com",
  databaseURL: "https://xxx.europe-west1.firebasedatabase.app",
});

const base = Rebase.createClass(firebaseApp.database());

export { firebaseApp }

export default base;

這是這種方法產生的錯誤:

TypeError: Cannot read properties of undefined (reading 'database')

這是 firebase V9 方法:

import Rebase from 're-base';
import { initializeApp } from 'firebase/app';
import { getDatabase } from 'firebase/database';

const firebaseApp = initializeApp({
  apiKey: "xxx",
  authDomain: "xxx.firebaseapp.com",
  databaseURL: "https://xxx.europe-west1.firebasedatabase.app",
});

const base = Rebase.createClass(getDatabase(firebaseApp));

export { firebaseApp }

export default base;

這是我在 v9 方法中遇到的錯誤:

REBASE: Rebase.createClass failed. Expected an initialized firebase or firestore database object.

據我所知,數據庫初始化良好。 我已經嘗試了整個 firebase / 初始化應用程序 / 從另一個組件中獲取數據庫步驟,控制台注銷了對我來說看起來像數據庫 object 的內容(但新手注意事項適用於此)

我錯過了什么? 我忽略了數據庫是否有一些明顯的配置步驟?

如何確認我的 firebase 數據庫實際上已初始化? 為什么 Rebase 在背后如此痛苦?

以供參考:

firebase:v9.9.4 / 變基:v4.0

@efreeman,您的問題是 Firebase 9 的更新。您需要使用課程starter files中提供的 Firebase 8.10.0。

https://github.com/wesbos/React-For-Beginners-Starter-Files/blob/master/catch-of-the-day/package.json

您可以恢復package.json文件並重新安裝 npm 包。

Re-base不兼容Firebase 9

暫無
暫無

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

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