我已经开始迁移到v9模块防火墙了。请看我的配置:
import { initializeApp } from 'firebase/app';
import { getDatabase } from "firebase/database";
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
..
};
const app = initializeApp(firebaseConfig);
// Get a reference to the database service
export const database = getDatabase(app);然后,在另一个文件中,我创建了基本的CRUD函数。
import { database } from "./firebase"
export const insertTestData = () => {
return database.ref("test").set({name:"hello world"})
}我得到了以下错误:
Uncaught TypeError: _firebase__WEBPACK_IMPORTED_MODULE_0__.database.ref is not a function我错过什么了吗?
我不知道为什么它也不增加进口

发布于 2022-02-17 16:16:09
您正在从Modular导入ref(),但仍然使用名称间隔语法。尝试:
import { getDatabase, ref, set } from "firebase/database";
export const insertTestData = () => {
return set(ref(database, "test"), { name: "hello" })
}确保您引用的是文档中代码段的“模块”选项卡。
https://stackoverflow.com/questions/71161632
复制相似问题