[英]Struggling to get re-base to recognise my initialized firebase DB
I'm working through some ReactJS tutorials, I've gone through them before but I'm having a bit of a refresh because it's been a while since I've had any reason to use ReactJS at all.我正在研究一些 ReactJS 教程,我之前已经看过它们,但我有一点更新,因为我已经有一段时间没有理由使用 ReactJS 了。 Something has changed with firebase / rebase since the last time I looked at it, and the sample code does not do the job I need it to do any more.
自从我上次查看以来,firebase / rebase 发生了一些变化,并且示例代码无法完成我需要它做的工作。
This is the code using the compatibility versions of firebase这是使用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;
This is the error this approach produces:这是这种方法产生的错误:
TypeError: Cannot read properties of undefined (reading 'database')
This is the firebase V9 approach:这是 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;
This is the error I'm getting for the v9 approach:这是我在 v9 方法中遇到的错误:
REBASE: Rebase.createClass failed. Expected an initialized firebase or firestore database object.
As far as I can tell, the DB initialises fine.据我所知,数据库初始化良好。 I've tried the whole firebase / initialize app / get database steps from within another component and console logged out what looks like a database object to me (but newbie caveats apply here)
我已经尝试了整个 firebase / 初始化应用程序 / 从另一个组件中获取数据库步骤,控制台注销了对我来说看起来像数据库 object 的内容(但新手注意事项适用于此)
What am I missing?我错过了什么? Is there some obvious configuration step with the DB that I've overlooked?
我忽略了数据库是否有一些明显的配置步骤?
How can I confirm that my firebase DB is actually initialized at all?如何确认我的 firebase 数据库实际上已初始化? Why is Rebase being such a pain in the backside?
为什么 Rebase 在背后如此痛苦?
for reference:以供参考:
firebase: v9.9.4 / rebase: v4.0
firebase:v9.9.4 / 变基:v4.0
@efreeman, your issue is the update to Firebase 9. You need to use Firebase 8.10.0 that is provided in the course starter files
. @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 https://github.com/wesbos/React-For-Beginners-Starter-Files/blob/master/catch-of-the-day/package.json
You can revert your package.json
file and re-install the npm packages.您可以恢复
package.json
文件并重新安装 npm 包。
Re-base
is not compatible with Firebase 9
Re-base
不兼容Firebase 9
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.