dina omari
dina omari

Reputation: 61

FirebaseError: "projectId" not provided in firebase.initializeApp

I'm trying to run my first reactjs template but i'm getting this error :

FirebaseError: "projectId" not provided in firebase.initializeApp.

and i have no idea how it will run with firebase or without it

Upvotes: 5

Views: 11970

Answers (4)

Shreyder
Shreyder

Reputation: 25

I've had the same Error. Solution and cause of the problem are:

Cause in official Firebase documentation (https://firebase.google.com/docs/web/module-bundling?hl=en&authuser=0) you may see the following line: const firebaseApp = initializeApp({ /* config */ });

You may copy it and paste in your project replacing the commented part "/* config */" - and this will work,

but if you have declared your configurations as a variable earlier like this:

var firebaseConfig = { apiKey: "API_KEY", authDomain: "PROJECT_ID.firebaseapp.com", databaseURL: "https://DATABASE_NAME.firebaseio.com", projectId: "PROJECT_ID", ... };

Solution: you must erase the curly brackets as well.

It is a kinda dumb error but if you don't catch it right away you loose quite a time finding the cause of the error.

Upvotes: -1

Adam Beleko
Adam Beleko

Reputation: 771

Got the same and decided to force it:

import {initializeApp} from 'firebase/app';
import {getFirestore} from 'firebase/firestore';

const firebaseConfig = JSON.parse(
    process?.env?.FIREBASE_CONFIG ?? '{}',
);

const app = initializeApp({...firebaseConfig, projectId: firebaseConfig?.projectId});

In my case, I was converting my config json from its string form (JSON.parse).

Upvotes: 0

sillo01
sillo01

Reputation: 614

Added the automatic initialization scripts to index.html. Works for local dev running the app with npm start. Should also work when deployed to firebase.

<body>
 <div id="root"></div>
 <script src="/__/firebase/7.19.1/firebase-app.js"></script>
 <script src="/__/firebase/init.js"></script>
</body>

In the sources, I initialized firebase passing only projectId.

const firebaseApp = firebase.initializeApp({
  projectId: '<PROJECT_ID>'
});

Upvotes: 0

Daniel Ballerini
Daniel Ballerini

Reputation: 73

I solved, with this:

<script src="https://www.gstatic.com/firebasejs/5.0.4/firebase.js"></script>
<script>
  // Initialize Firebase
  // TODO: Replace with your project's customized code snippet
  var config = {
    apiKey: "<API_KEY>",
    authDomain: "<PROJECT_ID>.firebaseapp.com",
    databaseURL: "https://<DATABASE_NAME>.firebaseio.com",
    projectId: "<PROJECT_ID>",
    storageBucket: "<BUCKET>.appspot.com",
    messagingSenderId: "<SENDER_ID>",
  };
  firebase.initializeApp(config);
</script>

Link help

Upvotes: 7

Related Questions