firebase - 在本地运行 firebase 触发事件
问题描述
我有一个简单的方法,比如
exports.updatePlayer = functions.firestore
.document('matches/{docId}')
.onCreate((change, context) => {
console.log('fired------------', context.params.docId);
});
如果我向匹配项添加新文档,我可以在日志中看到控制台消息。
问题是我如何在本地运行它?我在 package.json 中有这个 cmd
"serve": "firebase emulators:start --only functions,database",
当我运行“npm run server”时,控制台说
> functions@ serve D:\cric\fs-functions\functions
> firebase emulators:start --only functions,database
i emulators: Starting emulators: functions
! database: Not starting the database emulator, make sure you have run firebase init.
+ hub: emulator hub started at http://localhost:4400
! Your requested "node" version "8" doesn't match your global version "12"
+ functions: functions emulator started at http://localhost:5001
i functions: Watching "D:\cric\fs-functions\functions" for Cloud Functions...
! functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production.
+ functions[allMatches]: http function initialized (http://localhost:5001/xxxx-xxxxx/us-central1/allMatches).
i functions[updatePlayer]: function ignored because the firestore emulator does not exist or is not running.
+ emulators: All emulators started, it is now safe to connect.
但是现在,如果我向 firestore 集合添加一些东西,我的本地终端上不会收到任何控制台消息。也不是这样
i functions[updatePlayer]: function ignored because the firestore emulator does not exist or is not running.
我想在本地运行这个触发器,所以可以快速编写/测试我的代码。
解决方案
尝试更新您的 NodeJs 版本
Firebase 宣布在 Cloud Functions 上弃用 Node.js 8 运行时并停用 Node.js 6 运行时。
为确保您的函数在受支持的 Node.js 版本上,请尽快迁移到 Node.js 10 运行时。
从 Node.js 8 更新到 Node.js 10,通过在engines
package.json
推荐阅读
- botframework - 使用 BotFramework Composer 在卡片之间发送值
- javascript - 使用内容恢复 GridstackJS 面板(例如 Highcharts)
- c# - 突然无法更改 HttpClient 上的超时
- javascript - 未捕获的语法错误:构建后出现意外的令牌“<”(Vue.js)
- android - 显示带有 recyclerview 和改造的图像
- ionic4 - 在 ionic 4 中网络离线时显示模式
- java - 如何拆分但不是所有字符
- php - 卷曲不启用 wamp
- python - 仅定义变量后无法访问对象宏中的变量(rivescript)
- symfony - Symfony 3:如何使用 Collection 并验证它