【问题标题】:Running a firebase trigger event locally在本地运行 firebase 触发事件
【发布时间】:2020-08-16 07:52:03
【问题描述】:

我有一个简单的方法,比如

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.

我想在本地运行这个触发器,这样可以快速编写/测试我的代码。

【问题讨论】:

  • 你有 --only functions,database 这意味着实时数据库(不是 Firestore)模拟器将运行。试试--only functions,firestore
  • @MichaelBleigh 同样的错误!!

标签: firebase google-cloud-functions firebase-cli


【解决方案1】:

尝试更新您的 NodeJs 版本

Firebase 宣布在 Cloud Functions 上弃用 Node.js 8 运行时并停用 Node.js 6 运行时。

为确保您的函数在受支持的 Node.js 版本上,请尽快迁移到 Node.js 10 运行时。

从 Node.js 8 更新到 Node.js 10,通过 setting the engines field in package.json 明确指定 Node.js 10 运行时

NodeJs End-of-Life Releases

【讨论】:

  • 我也支持这个,基于遇到的错误:Your requested "node" version "8" doesn't match your global version "12"
猜你喜欢
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
  • 2013-12-28
  • 1970-01-01
  • 2018-02-20
  • 2019-06-18
  • 1970-01-01
  • 2019-02-11
相关资源
最近更新 更多