【发布时间】:2018-01-21 08:34:18
【问题描述】:
我有非常简单的“Node.js functions.config()”代码,可以读取简单的属性值。
const smtpEmail = functions.config().smtp.email;
代码在早期的 Firebase 版本中运行,但是在更新到最新的 firebase 工具 v"3.17.3" 和 firebase-admin "5.8.1", firebase-functions "0.8.1" 后,我变得很顽固使用 functions.config() 解析错误
我在函数目录中多次运行firebase functions:config:get > .runtimeconfig.json,但当我尝试在本地运行函数时,Firebase 仍然抱怨以下错误消息。
! functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
! functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers.
TypeError: Cannot read property 'email' of undefined
at Object.<anonymous> (D:\android-projects\firebase\functions\index.js:85:42)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at C:\Users\GIGABYTE\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:18:11
at Object.<anonymous> (C:\Users\GIGABYTE\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:38:3)
这是生成的“.runtimeconfig.json”文件的格式。
{
"smtp": {
"email": "myemail@domain.com",
"password": "password"
}
}
【问题讨论】:
-
请编辑您的问题以显示失败的代码。
-
您的
.runtimeconfig.json在您的项目文件夹中的什么位置? -
它一直位于“functions”目录中,在更新 Firebase 工具之前,一切运行顺利,没有任何问题。
-
读取配置的代码行在哪里?在触发函数内部,还是在全局范围内?
-
代码刚更新就坏了,之前运行很流畅,解析器报错这些值不存在,const smtpEmail = functions.config().smtp.email; const smtpPassword = functions.config().smtp.password;
标签: node.js firebase firebase-realtime-database google-cloud-functions