我有非常简单的“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"
}
}