Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

93
Views
Getting error that Firebase Firestore imports are not declared even if in import statement

I'm trying to get a document from Firebase Firestore but every time I try getting it I get an error that my "onHomeLoad" function is not declared and if I put it in the console I then get either that doc() or getDoc() aren't declared. I tried everything I've found online but nothing worked.

My code:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.0/firebase-app.js";
import { getFirestore , getDoc , doc } from "https://www.gstatic.com/firebasejs/9.0.0/firebase-firestore.js";

const firebaseApp = initializeApp({
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: ""
});

const db = getFirestore(firebaseApp);

function onHomeLoad() {
    let siteSettingsHome = doc(db, 'siteSettings/home');
    getDocument(siteSettingsHome);
}
async function getDocument(docLocation) {
    let documentSnapshot = await getDoc(docLocation);
    if( homeSettingSnapshot.exists() ){
        let documentData = documentSnapshot.data();
        console.log(`Doc data: ${JSON.stringify( documentData )}`);
        return documentData;
    }
}

I've removed the stuff inside the initializeApp object here but it's filled correctly in my js document.

7 months ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.