1
votes

am getting this error while I'm trying to deploy to a new firebase project using firebase deploy --only functions command. I have two projects in use, one dev and one prod, I was working on prod and deploy worked well now too but when I added this project dev the deploying keeps working well in prod but in this new project dev no. I instead get this error:

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'environment' of undefined at Object. (/home/projectId/Bitbucket/project-backend/functions/lib/db.js:6:35)

I added the key and eveything in cert/dev/firebase-dev.json in order to work. The file db.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.db = void 0;
const admin = require("firebase-admin");
const functions = require("firebase-functions");
const dir = functions.config().app.environment;
const certFile = `firebase-${dir}.json`;
//using admin SDK
const serviceAccount = require(__dirname + `/../cert/${dir}/${certFile}`);
admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
.....

Any Idea? Thanks.

1
Can you show how did you set the environment configuration? And can you check it is correctly set in the dev environment/project with firebase functions:config:get? - Renaud Tarnec
Oh, thanks @RenaudTarnec I had a mistake in environment and now it worked! Thanks! - Malakmkd

1 Answers

2
votes

Since the error is cannot read property 'environment' of undefined and in your code we see

const dir = functions.config().app.environment;

the error seems to come from the environment configuration.


You should double check that the environment configuration is correctly set in the dev environment/project.

For that, you should use the firebase functions:config:get CLI command, as explained in the doc.