简体   繁体   English

无法在Node中调用firebase.database() function

[英]Can not call the firebase.database() function in Node

I have the following configuration file in my nodejs project我的 nodejs 项目中有以下配置文件

const firebase = require('firebase/app');

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "AIzaSyBNMB7IdCKV7iObJDSSFTRVHp9M8ZndpZh2c",
  authDomain: "ivrs-d422d.firebaseapp.com",
  databaseURL: "https://ivrs-d422d.firebaseio.com",
  projectId: "ivrs-d422d",
  storageBucket: "ivrs-d422d.appspot.com",
  messagingSenderId: "10387822329211",
  appId: "1:1038786929211:web:6ed1a58fewqa9855105ef21e",
  measurementId: "G-ZTY9VS9EK9"
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);

const db = firebase.database();

and i get the following error:我收到以下错误:

/Users/Documents/Market/config/firebaseConfiguration.js:26
  const db = firebase.database();
                      ^

TypeError: firebase.database is not a function
    at Object.<anonymous> 
(/Users/Documents/Market/config/firebaseConfiguration.js:26:23)

Can someone explain why that is happening?有人可以解释为什么会这样吗?

seems like you need to import getFirestore from firebase/firestore似乎您需要从 firebase/firestore 导入 getFirestore

then set db = getFirestore()然后设置 db = getFirestore()

check the docs, Id also recommend this series on fire base 9 https://youtu.be/2yNyiW_41H8检查文档,我也推荐这个系列在火基地 9 https://youtu.be/2yNyiW_41H8

from Net Ninja.来自网络忍者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM