Uncaught FirebaseError: projectId must be a string in FirebaseApp.options

Vladimir Strilets | Web Developer
2 min readMay 25, 2020

--

So, I was working on a React project and setting up my Firebase connection, and after firebase deploy — only hosting this happened:

It worked fine locally and please don’t start saying that I forgot my config file. Here it is:

import firebase from "firebase/app";
import "firebase/auth";
import "firebase/firestore";
const firebaseConfig = {
apiKey: "***",
authDomain: "***",
databaseURL: "***",
projectId: "***",
storageBucket: "***",
messagingSenderId: "***",
appId: "***",
measurementId: "***",
};
// Initialize Firebase instance
firebase.initializeApp(firebaseConfig);
// Initialize other services on firebase instance
firebase.firestore();
export default firebase;

So, what was the problem? The problem was that the firebase export was previously that initializeApp() had been completed. And then in my App.js I used uninitialized firebase. Sometimes page reloading fixed the problem, but I knew there was a problem.

So, what I did? I passed all the firebase imports and initialization directly to my App.js where I was using the firebase instance inside my Context Provider. Without any export default firebase.

Another alternative could be this (if I hadn’t needed firestore):

... 
export default firebase.initializeApp(firebaseConfig);

I hope it was useful. See you.

EDIT 11/10/2020

I have found another way to deal with firebase. We can just create a new variable with the initialized firebase and export it, not the imported firebase.

// firebase.jsimport firebase from "firebase/app"
import "firebase/auth"
const firebaseConfig = {...}const firebaseApp = firebase.initializeApp(firebaseConfig)export const auth = firebaseApp.auth()export default firebaseApp

And then, somewhere in your code:

import firebase, { auth } from "...../firebase.js"
// here firebase is the firebaseApp, the default exported instance

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response