【问题标题】:Error integrating firebase into react app将 Firebase 集成到 React 应用程序时出错
【发布时间】:2018-07-04 05:55:29
【问题描述】:

我在尝试构建我的 React 应用程序时遇到此错误。自构建失败以来唯一改变的是我尝试向应用程序添加一个 Firebase 数据库。我正在尝试以我在使用的教程中找到的相同方式来实现它。

×
REBASE: Rebase.createClass failed. Expected an initialized firebase or firestore database object.
▶ 3 stack frames were collapsed.
./src/base.js
C:/Dev/React/my-app/src/base.js:3
  1 | import Rebase from 're-base';
  2 | 
> 3 | const base = Rebase.createClass({
  4 |   apiKey: "AIzaSyC1UGLssKKLkKvYRp02zYVpM1-D88czp7I",
  5 |   authDomain: "catch-of-the-day-ethan-fie.firebaseapp.com",
  6 |   databaseURL: "https://catch-of-the-day-ethan-fie.firebaseio.com",

来自 base.js 的代码如下,个人信息和 API 密钥已编辑:

import Rebase from 're-base';

const base = Rebase.createClass({
  apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  authDomain: "catch-of-the-day-xxxxx-xxxx.firebaseapp.com",
  databaseURL: "https://catch-of-the-day-xxxxx-xxxx.firebaseio.com",
  projectId: "catch-of-the-day-xxxxx-xxxx",
  storageBucket: "catch-of-the-day-xxxxx-xxxx.appspot.com",
});

export default base;

【问题讨论】:

  • 请查看本指南,看看您是否做得对。 coderjourney.com/tutorials/how-to-integrate-react-with-firebase
  • 这行得通。看来我使用的是 re-base 库版本 2 中的语法。
  • 很高兴知道它有助于解决问题。请将我发布的答案标记为正确且有用的答案,以供其他人知道,遇到类似问题。

标签: reactjs firebase firebase-realtime-database


【解决方案1】:

给你

import Rebase from 're-base'
import firebase from 'firebase'

const config = {
  apiKey: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
  authDomain: "catch-of-the-day-xxxxx-xxxx.firebaseapp.com",
  databaseURL: "https://catch-of-the-day-xxxxx-xxxx.firebaseio.com",
  projectId: "catch-of-the-day-xxxxx-xxxx",
  storageBucket: "catch-of-the-day-xxxxx-xxxx.appspot.com",
  messagingSenderId: "SOME_MESSAGING_SENDER_ID"
}

const app = firebase.initializeApp(config)
const base = Rebase.createClass(app.database())


export default base;

【讨论】:

    【解决方案2】:

    请查看此指南以解决问题。

    https://coderjourney.com/tutorials/how-to-integrate-react-with-firebase/

    确保您使用上述参考中提到的正确库版本语法。

    【讨论】:

      【解决方案3】:

      试试这个,它会起作用的:

      var Rebase = require('re-base');
      var firebase = require('firebase/app');
      var database = require('firebase/database');
      var app = firebase.initializeApp({
        apiKey: "apiKey",
        authDomain: "projectId.firebaseapp.com",
        databaseURL: "https://databaseName.firebaseio.com",
        storageBucket: "bucket.appspot.com",
        messagingSenderId: "xxxxxxxxxxxxxx"
      });
      var db = firebase.database(app);
      var base = Rebase.createClass(db);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多