【问题标题】:firebase cloud functions: cannot read property 'environment' of undefinedfirebase 云功能:无法读取未定义的属性“环境”
【发布时间】:2021-07-15 10:47:31
【问题描述】:

我在尝试使用部署到新的 firebase 项目时遇到此错误 firebase deploy --only 函数命令。我有两个正在使用的项目,一个开发和一个产品,我正在从事产品和部署工作,现在也运行良好,但是当我添加这个项目开发时,部署在产品中继续运行良好,但在这个新项目开发中没有。相反,我得到了这个错误:

错误:解析函数触发器时出错。

TypeError:无法读取未定义的属性“环境” 在对象。 (/home/projectId/Bitbucket/project-backend/functions/lib/db.js:6:35)

为了工作,我在 cert/dev/firebase-dev.json 中添加了密钥和所有内容。 文件 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),
.....

有什么想法吗?谢谢。

【问题讨论】:

  • 你能展示一下你是如何设置环境配置的吗?你能用firebase functions:config:get检查它在开发环境/项目中是否正确设置?
  • 哦,谢谢@RenaudTarnec 我在环境中有一个错误,现在它可以工作了!谢谢!

标签: database typescript firebase google-cloud-functions


【解决方案1】:

由于错误是 cannot read property 'environment' of undefined 并且在您的代码中我们看到

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

错误似乎来自环境配置。


您应该仔细检查环境配置是否正确设置在开发环境/项目中

为此,您应该使用firebase functions:config:get CLI 命令,如doc 中所述。

【讨论】:

    猜你喜欢
    • 2018-12-05
    • 2020-05-18
    • 1970-01-01
    • 1970-01-01
    • 2019-01-23
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多