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

155
Vistas
i cannot connect firebase to my html file

i am doing net ninjas JS course and in that there's a chapter for databases that uses firebase. but his code for firebase is fairly different from now and I'm struggling with npm and node.js. I followed the documentation from this and I'm getting an "Uncaught SyntaxError: Cannot use import statement outside a module". but when I add type="module" to app.js I get a different error "Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../"." below is my code:-

HTML :-

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script src="app.js"></script>
</body>
</html>

JS:-

// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getFirestore, collection, getDocs } from '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
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "AIzaS.....bFkMOXoRY",
  authDomain: "modern.....irebaseapp.com",
  projectId: "mode....nja",
  storageBucket: "modern-j......ja.appspot.com",
  messagingSenderId: "9635.....932978",
  appId: "1:96350793.......cbf567939ae91512b",
  measurementId: "G-HFN5111EHZ"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);

everything is copy-pasted from the app that I created. please help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Can you change your imports to this:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js";
import { getFirestore, collection, getDocs  } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-firestore.js";

You can find more info about it here.

You are using browser modules so you need to use those imports. This is what stands in the docu about it:

enter image description here

about 4 years ago · Juan Pablo Isaza Denunciar
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