Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
Firebase is expecting the first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

I am trying to initialize the Admin SDK in a NextJS app. I have initialized the app as so:

import { getFirestore } from '@firebase/firestore';
import admin from 'firebase-admin';

if (!admin.apps.length) {
  admin.initializeApp({
    credential: admin.credential.cert({
      project_id: process.env.NEXT_PUBLIC_PROJECT_ID,
      private_key: process.env.FIREBASE_PRIVATE_KEY,
      client_email: process.env.FIREBASE_CLIENT_EMAIL
    })
  });
}

export default getFirestore();

and then try to use the database in the following code snippet:

import { getDocs, collection } from '@firebase/firestore';
import db from '@/lib/firebase-admin';

export default async (_, res) => {
  let sites = [];

  const querySnapshot = await getDocs(collection(db, 'sites'));
  querySnapshot.forEach((doc) => {
    sites.push(doc.id, ...doc);
  });

  res.status(200).json(sites);
};

But I am presented with the following error: Next JS Firebase Error

FirebaseError: Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore

I am using the Web V9 (module) components of Firebase, and have yet to figure out why I am getting this error. Any help would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda