【发布时间】:2021-11-09 05:54:25
【问题描述】:
出现错误的代码:
const user = db.collection("users").doc(`${match.params.id}`).get();
错误:
TypeError: _firebase_config__WEBPACK_IMPORTED_MODULE_1__.db.collection is not a function
这是firebase-config.js:
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
import { getAuth } from "firebase/auth";
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
apiKey: "xxxxxxxxxx",
authDomain: "xxxxxxx.firebaseapp.com",
projectId: "PROJECT-ID",
storageBucket: "xxxxxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxxx",
appId: "xxxxxxxxxxx",
measurementId: "xxxxxxxxx",
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getFirestore(app);
const auth = getAuth(app);
export { analytics, auth, db };
尝试:
重新安装 Firebase,不行 重新安装所有模块(删除 node_modules 文件夹和 npm install ),Nopes
【问题讨论】:
-
这是一个普通的firebase应用程序,不是firebase管理员,我使用的是Firebase 9.0.2,所以语法不同+我没有使用实时数据库我使用的是Firestore
标签: reactjs firebase google-cloud-firestore