使用 FirebaseDatabaseNode 时出现“TypeError: firebase.database is not a function error”

时间:2021-07-21 18:28:46

标签: reactjs firebase firebase-realtime-database

我想通过这条指令https://react-firebase-js.com/docs/react-firebase-realtime-database/getting-started

连接我在firebase中的实时数据库并做出反应

但是当我使用“FirebaseDatabaseNode”时,我收到了这个错误。

我已经使用这个插件成功地实现了身份验证。

我的 app.js


import './App.css';
import firebase from "firebase/app";
import "firebase/auth";
import Home from './components/Home';
import React from 'react';
import Login from './components/login/Login';
import { FirebaseAuthConsumer, FirebaseAuthProvider } from '@react-firebase/auth';
import { FirebaseDatabaseProvider, FirebaseDatabaseNode } from "@react-firebase/database";
function App() {
  let _firebaseConfig = {
    apiKey: "My apiKey",
    authDomain: "my authDomain",
    databaseURL: "my databaseURL",
    projectId: "my projectid",
    storageBucket: "my storageBucket",
    messagingSenderId: "my messagingSenderId",
    appId: "my appId",
    measurementId: "my measurementId"
  };
  return (
    <FirebaseAuthProvider firebase={firebase} {..._firebaseConfig}>
      {
        <FirebaseDatabaseProvider firebase={firebase} {..._firebaseConfig}>
          <FirebaseDatabaseNode
            path="exchange_rate/"
          // limitToFirst={this.state.limit}
          // orderByKey
          // orderByValue={"created_on"}
          >
            {d => {
              return (
                <React.Fragment>
                  <pre>Path {d.path}</pre>
                  <pre style={{ height: 300, overflow: "auto" }}>
                    Value {(d.value)}
                  </pre>
                </React.Fragment>
              );
            }}
          </FirebaseDatabaseNode>
        </FirebaseDatabaseProvider>
      }
    </FirebaseAuthProvider>

  );
}

export default App;

1 个答案:

答案 0 :(得分:2)

尝试导入数据库模块本身

import "firebase/database"