Firebase 的 Cloud Functions 无法模拟

Posted

技术标签:

【中文标题】Firebase 的 Cloud Functions 无法模拟【英文标题】:Cloud Functions of Firebase failed to emulate 【发布时间】:2018-09-10 09:34:42 【问题描述】:

当我尝试运行npm run serve:

"build": "./node_modules/.bin/tsc",
"serve": "npm run build && firebase serve --only functions",

我得到一个输出,说它无法模拟我的功能:

> npm run build && firebase serve --only functions


> functions@ build /Users/eliyacohen/apps/app-name/functions
> tsc


=== Serving from '/Users/eliyacohen/apps/app-name'...

i  functions: Preparing to emulate functions.
⚠  functions: Failed to emulate payment-create
⚠  functions: Failed to emulate payment-process

当我打开firebase-debug.log 了解更多信息时,我看到:

...
Sat Mar 31 2018 18:48:05 GMT+0300 (IDT)
[debug] [2018-03-31T15:48:06.665Z] <<< HTTP RESPONSE 200
[debug] [2018-03-31T15:48:06.666Z] Starting @google-cloud/functions-emulator
[debug] [2018-03-31T15:48:08.254Z] Parsing function triggers
[debug] [2018-03-31T15:48:10.194Z] Error while deploy to emulator: Error: connect ECONNREFUSED 127.0.0.1:5001
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
[debug] [2018-03-31T15:48:10.195Z] Error while deploy to emulator: Error: connect ECONNREFUSED 127.0.0.1:5001
at Object.exports._errnoException (util.js:1020:11)
at exports._exceptionWithHostPort (util.js:1043:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)
[warn] ⚠  functions: Failed to emulate payment-create
[warn] ⚠  functions: Failed to emulate payment-process

据我了解,它无法到达 127.0.0.1:5001 所以它可以在本地提供这些功能?

我知道我的代码没有问题,因为 firebase deploy --only functions 部署我的函数时没有错误。

我尝试完全删除 Node.js 并重新安装、降级和升级它。全局模块也是如此。

我的主文件夹 (../functions) 是基于 Ionic 框架构建的。跟这个有关系吗?

环境:

在 MacOS High Sierra 上运行 Node.js v6.11.5 NPM 版本 3.10.10 firebase 工具:3.17.7(全球) firebase 管理员:^5.11.0, firebase 功能:^0.9.1

【问题讨论】:

您是否也尝试过重启? 遇到同样的问题,当我从另一个较旧的 firebase 项目中复制并粘贴我的节点模块时,firebase 服务模拟了这些功能...... prob 应该在 github 上打开一个问题 你们找到这个解决方案/更新了吗?一直在部署函数来测试它真的很伤心 @GuilhermeMatuella 尝试更新到节点 10,重新启动 pc,删除节点模块,然后再次 npm 安装。确保你的依赖是最新的 @Marco 看看 cmets。升级到最新版本的 nodejs 解决了这个问题。 【参考方案1】:

由于我看到很多人仍然遇到以下错误,请尝试将您的节点版本更新为最新的稳定版本(或 >= 10)

【讨论】:

【参考方案2】:

尝试使用不同的端口。例子

firebase serve --port 3000 --only functions

【讨论】:

错误提示它无法连接到 emulator,这可能不是一个正确的答案 - 但一个很好的故障排除技术。

以上是关于Firebase 的 Cloud Functions 无法模拟的主要内容,如果未能解决你的问题,请参考以下文章

如何从 Cloud Function 调用其他 Cloud Firebase Functions

在 Cloud Function for Firebase 中设置 Firebase 消息的优先级

是否可以检索 Firebase Cloud Function 源代码?

Firebase Cloud Function 部署 tslint 错误

Firebase:Firestore 未在 Cloud Function 的计划函数中更新数据

从请求中获取用户信息到 Firebase 中的 Cloud Function