Reputation: 329
I am learning firebase. I am using Kubuntu 21.04.
I installed nodejs and npm using :
sudo apt install nodejs npm
I created a project folder with index.html file /home/username/project/index.html
.
I have also installed firebase using npm install firebase
while I was on project folder in terminal.
I follow upto STEP 2 as given in https://firebase.google.com/docs/web/setup.
My index.html content-
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>User Auth</title>
</head>
<body>
<h1>User Auth</h1>
<script>
// Import the functions you need from the SDKs you need
import { initializeApp } from "firebase/app";
import { getAnalytics } from "firebase/analytics";
// 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: "AIzaSyC5zv8b1wfc0ykmpULeFI6tJa6Grk",
authDomain: "user-auth-75223.firebaseapp.com",
projectId: "user-auth-78563",
storageBucket: "user-auth-78563.appspot.com",
messagingSenderId: "482788408547",
appId: "1:482788408547:web:89e3ecdc24f3454576c00aa",
measurementId: "G-VK5D45CCJ2"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
</script>
</body>
</html>
But when I run above html file in chrome. It is giving error in chrome's console.
Uncaught SyntaxError: Cannot use import statement outside a module
Upvotes: 3
Views: 4450
Reputation: 31
It's probably because you did not add
"type":"module"
in package.json?
I fixed this issue by adding this line
source: (node:9374) Warning: To load an ES module, set "type": "module"
Upvotes: 3