Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

319
Views
unhandledRejection: ReferenceError: no se puede acceder a 'firestore' antes de la inicialización

Soy muy nuevo en next.js y estoy desarrollando una API con él, aparte de esa API quiero usar firebase, así que configuré firebase pero cuando intento llamarlo, aparece este error: "unhandledRejection: ReferenceError : No se puede acceder a 'firestore' antes de la inicialización"

Código a continuación.

Archivo de configuración de Firebase

 import firebase from 'firebase/app'; import "firebase/firestore"; // For Firebase JS SDK v7.20.0 and later, measurementId is optional const firebaseConfig = { apiKey: "*******", authDomain: "********", projectId: "*****", storageBucket: "*****", messagingSenderId: "****", appId: "****", measurementId: "****" }; //if(!firebase.apps.length){ //} firebase.initializeApp(firebaseConfig); const firestore = firebase.firestore(); export { firestore };

Servicio de almacenamiento de fuego

 import { firestore } from './firebase'; export class Firestore { async getOne(collection, uid){ const data = await firestore.collection(`${collection}/${uid}`).get(); return await data.docs(); } }

página de la API

 import {Firestore} from '../../utils/firestore'; const firestore = new Firestore(); const getBanners = () => { return firestore.getOne('settings','client'); //return data; } export default function Handler(req,res){ res.status(200).json({ 'name':"getBanners", 'data': getBanners() }); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Resolví este problema agregando import firebase from 'firebase/compat/app'; y también import 'firebase/compat/firestore'; . ¡Y funciona!

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!