i wanna use firebase but i constantly get the
firebase.firestore is not a function
this is my js file where i want to add things to my firebase
import 'firebase/firestore';
import 'firebase/auth';
export function seedDatabase(firebase) {
function getUUID() {
// eslint gets funny about bitwise
/* eslint-disable */
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
const piece = (Math.random() * 16) | 0;
const elem = c === 'x' ? piece : (piece & 0x3) | 0x8;
return elem.toString(16);
});
/* eslint-enable */
}
/* Series
============================================ */
// Documentaries
firebase.firestore().collection('series').add({
id: getUUID(),
title: 'Tiger King',
description: 'An exploration of big cat breeding and its bizarre underworld, populated by eccentric characters.',
genre: 'documentaries',
maturity: '18',
slug: 'tiger-king',
}); }
this is my js file where i want to connect to my firebase cloud
import { seedDatabase } from "../seed";
/// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import 'firebase/firestore';
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "x",
authDomain: "x",
projectId: "x",
storageBucket: "x",
messagingSenderId: "x",
appId: "x"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
seedDatabase(app)
i searched through many stackpages but i didn’t find my answer
2
Answers
You are trying to use the version 8 style of API with the version 9 SDK. That won’t work. The APIs are completely different in v9.
When following the Firebase documentation, you should make sure to use the v9 code samples by selecting the correct tab. For example, to add a new document, the code will look like this:
if you are going to use version 9 it is configured in this way, you can initialize the configuration You will have to import Cloud Firestore js/firebase.js
Initialize Firebase
initialize Cloud Firestore and get a reference to the service
now in to call the add() method