【发布时间】:2018-10-20 06:13:55
【问题描述】:
我正在我现有项目中使用 typescript 本地测试 firebase 功能。当我运行以下命令时,即使我可以将其上传到 firebase 项目,我总是会收到 typeerror。 typescript编译成js后总是出现这个错误
firebase serve --only functions
TypeError:无法读取未定义的属性“用户名” 在对象。 (C:\Users\phone\Desktop\VMS\mynewvm_functions\functions\lib\email\index.js:8:52) 在 Module._compile (module.js:635:30) 在 Object.Module._extensions..js (module.js:646:10) 在 Module.load (module.js:554:32) 在 tryModuleLoad (module.js:497:12) 在 Function.Module._load (module.js:489:3) 在 Module.require (module.js:579:17) 在要求(内部/module.js:11:18) 在对象。 (C:\Users\phone\Desktop\VMS\mynewvm_functions\functions\lib\index.js:19:15) 在 Module._compile (module.js:635:30)
import * as functions from 'firebase-functions';
import * as nodemailer from 'nodemailer';
const accountname = functions.config().emailaccount.username;
const accountpassword = functions.config().emailaccount.password;
/* smtp configuration */
我已经在我的项目中设置了 emailaccount,下面是我的代码。
firebase functions:config:set emailaccount.username="email@domain.com"
emailaccount.password="mypassword"
请注意,它在上传到 firebase 函数时工作正常,但在本地服务时却不行。我该怎么做才能让它在本地工作?
最后,我只是将所有凭据替换为实际值,而不是从 firebase 配置中获取。然后我 cd 到函数文件夹并输入'npm start'。看起来当我运行'firebase serve --only functions' 时,它不适用于最近的更改,所以在我输入'npm start' 之前给我同样的错误,这将运行tsc 和firebase shell,停止它(ctrl+c)然后输入'firebase serve --only functions'再次。仅供参考,我使用 firebase cli 和 typescript 创建了我当前的 firebase 函数项目。
firebase cli - 3.18.4
firebase functions - ^1.0.1
firebase admin - 5.12.0
@google-cloud/storage - 1.6
【问题讨论】:
标签: firebase google-cloud-functions