Firebase Functions Deploy Failed: Error Precondition failed

The Problem

Recently, I encountered an issue where firebase deploy or firebase deploy --only functions kept failing with a Error Precondition failed error. After hours of debugging and searching through GitHub issues, I found the root cause was related to an outdated initialization pattern in Firebase Functions.

The Common Culprit

If you’re seeing this error, check if you have code that looks like this in your functions:

firebase.initializeApp(functions.config().firebase);

because from firebase functions V2, this is no longer supported, which will actually cause deploy error.

Instead use progress.env.YOUR_SECRET_STRING.

This should not be used in any part of your functions file. I was using it outside of individual functions, thinking this wouldn’t be a problem. But it turned out to be wrong.

Hope it helps.