Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

279
Visualizações
Why does firebase.initializeApp not work?

I've basically copy and pasted the exact code from the firebase documentation on how to set up firestore. When I try to run my, app, I get a breaking error, which says my app has not been initialized.

here is my firebase.js config file:

import { initializeApp } from "firebase/app";
import { fbConfig } from "./secrets.js"
import { getFirestore } from "firebase/firestore";

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

console.log(firebaseApp)
export default getFirestore()

For comparison, here is a link to the firebase docs. My console log is returning this:

FirebaseAppImpl {_isDeleted: false, _options: {…}, _config: {…}, _name: '[DEFAULT]', _automaticDataCollectionEnabled: false, …}
{...}
[[Prototype]]: Object

Here is the code where firebase is being called, in a different file:

import { useState, useEffect } from "react";
import { useForm } from "react-hook-form";
import { doc, setDoc } from "firebase/firestore";
import db from "../firebase" 
//I'm expecting db to be my exported firestore call from firebase.js

function Admin() {
  const onFormSubmit = async (data) => {
    await setDoc(doc(db, "interviewees", data.name), {
      name: data.name,
      location: data.location,
      age: data.age,
    });
  };

  return(<a big component>)
}

When the Admin component renders, this error appears:

errors.ts:91 Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).

so, it looks to my like there is an app being initialized. But my app crashing and the error message seems to disagree with my assessment. I'd appreciate any help!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Looks like I just had to delete my node modules and package log and npm install... 🙃

about 4 years ago · Juan Pablo Isaza Relatório

0

Try to return db not called function like export default getFirestore()

const firebaseApp = initializeApp({...});

const db = getFirestore() // In this line function are assigning database to a variable.

export { db }

Example of usage db:

import { addDoc, collection } from 'firebase/firestore'
import { db } from '...../firebase.js' // change path to your file

function addDocument(path, data) {
   addDoc(collection(db, path), data)
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda