-1

in my script.js

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js";
 import { getDatabase, ref, set, child, get } from "https://www.gstatic.com/firebasejs/9.4.1/firebase-database.js";


 // Initialize Firebase
 const app = initializeApp(firebaseConfig);
 const db = getDatabase(app);
 const dbRef = ref(db);

is showing error SyntaxError: Cannot use import statement outside a module how do I solve this

Roy Sougat
  • 83
  • 7

1 Answers1

1

It sounds like you're using import in a script, not a module. The distinction is in how the environment was told to load the file.

In a browser, you need type="module" on the script tag:

<script src="./script.js" type="module"></script>

More on MDN.

On Node.js, you need "type": "module" in your package.json or the .mjs extension, see the Node.js documentation for details.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875