我有一个Firebase函数API项目,但无法启动Firebase模拟器。
当我编译并运行时:
npm run build
Firebase serve —only functions
我得到以下输出:
> functions@ build /Users/gibranshah/repos/eva-heart-functions/EVA-Heart-Functions/functions
> tsc
=== Serving from '/Users/gibranshah/repos/eva-heart-functions/EVA-Heart-Functions'...
i functions: Preparing to emulate functions.
Warning: You're using Node.js v8.12.0 but Google Cloud Functions only supports v6.11.5.
⚠ 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. Error occurred while parsing your function triggers.
TypeError: Cannot read property 'key' of undefined
at Object.<anonymous> (/Users/gibranshah/repos/eva-heart-functions/EVA-Heart-Functions/functions/lib/triggers/machine-learning-triggers.js:6:53)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/Users/gibranshah/repos/eva-heart-functions/EVA-Heart-Functions/functions/lib/index.js:27:20)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Module.require (module.js:597:17)
at require (internal/module.js:11:18)
该错误告诉我“无法读取未定义的属性'key'”,它将我定向到machine-learning-triggers.js中的这一行:
const SENDGRID_API_KEY = functions.config().sendgrid.key;
因此,functions.config()返回未定义sendgrid且密钥不存在的内容(或不包含任何内容)。
我知道由于权限问题(我们正在努力),我无法将仿真器连接到它使用的数据库。
所以我的问题是:当模拟器未连接到数据库或连接到错误的数据库时,是否会出现此错误?
我也无法完成Firebase初始化。我可以选择要使用的功能(我只选择功能),然后它中止给我错误:
Error: HTTP Error: 500, An unknown error occurred. Please contact support.
我想知道这是否也是由于未设置有效的数据库项目引起的。
我问这个问题的原因是决定我应该继续解决此问题还是只是等到经理授予我对数据库的访问权。我知道我最终必须连接到数据库,但是如果不知道此错误是由于缺少数据库连接(或连接到错误的数据库)引起的,则值得进一步进行故障排除。