-
Couldn't load subscription status.
- Fork 217
Description
Related issues
Probably related: Feature Request: Params #1084
Version info
node: v16.15.0
firebase-functions: 3.18.0
firebase-tools: 11.9.0
firebase-admin: 11.0.1
Test case & Steps to reproduce
Test Nr.1
# .env
DATA='data'// functions/receive.ts
import { https } from 'firebase-functions';
console.log(process.env.DATA);
export const httpsOnRequest = https.onRequest(async (req, res) => {
console.log(process.env.DATA);
res.status(200);
});Here everything is fine. I got the correct console output from all scopes.
Test Nr.2
# .env
GOOGLE_APPLICATION_CREDENTIALS=firebase.admin.json// functions/receive.ts
import { applicationDefault, initializeApp } from 'firebase-admin/app';
import { https } from 'firebase-functions';
initializeApp({
credential: applicationDefault(),
databaseURL: 'database_url',
});
export const httpsOnRequest = https.onRequest(async (req, res) => {
res.status(200);
});Everything is still fine. Credential is loaded from firebase.admin.json and the admin SDK can be used.
Test Nr.3
# .env
CREDENTIALS_ADMIN_PROJECT_ID='project_id'
CREDENTIALS_ADMIN_CLIENT_EMAIL'client_email'
CREDENTIALS_ADMIN_PRIVATE_KEY='private_key'
CONFIG_FIREBASE_DATABASE_URL='datbase_url'import { initializeApp } from 'firebase-admin';
import { cert } from 'firebase-admin/app';
import { https } from 'firebase-functions';
initializeApp({
credential: cert({
projectId: process.env.CREDENTIALS_ADMIN_PROJECT_ID,
clientEmail: process.env.CREDENTIALS_ADMIN_CLIENT_EMAIL,
privateKey: process.env.CREDENTIALS_ADMIN_PRIVATE_KEY,
}),
databaseURL: process.env.CONFIG_FIREBASE_DATABASE_URL,
});
export const httpsOnRequest = https.onRequest(async (req, res) => {
res.status(200);
});Here everything goes down the drain. On deploy it fails with Error: Failed to load function definition from source: Failed to generate manifest from function source: Error: Service account object must contain a string "project_id" property.. For some inexplicable reason the environment variables are all empty.
Summarized: Firebase does collect the environment path from GOOGLE_APPLICATION_CREDENTIALS but does not use custom environment variables.
Test Nr.4
# .env
CREDENTIALS_ADMIN_PROJECT_ID='project_id'
CREDENTIALS_ADMIN_CLIENT_EMAIL'client_email'
CREDENTIALS_ADMIN_PRIVATE_KEY='private_key'
CONFIG_FIREBASE_DATABASE_URL='datbase_url'import { initializeApp } from 'firebase-admin';
import { App, cert } from 'firebase-admin/app';
import { https } from 'firebase-functions';
class Application {
private app?: App;
get get() {
if (!this.app) {
this.app = initializeApp({
credential: cert({
projectId: process.env.CREDENTIALS_ADMIN_PROJECT_ID,
clientEmail: process.env.CREDENTIALS_ADMIN_CLIENT_EMAIL,
privateKey: process.env.CREDENTIALS_ADMIN_PRIVATE_KEY,
}),
databaseURL: process.env.CONFIG_FIREBASE_DATABASE_URL,
});
}
return this.app;
}
}
const application = new Application();
export const httpsOnRequest = https.onRequest(async (req, res) => {
application.get;
res.status(200);
});This works and is the current solution, because the environment only gets loaded on the first request.
Expected behavior
Function should load environment variable at deploy time and deploy without failure.
Actual behavior
Environment variables are not loaded and deploy fails.
Were you able to successfully deploy your functions?
Yes. Not using environment variables or load on first request.