【发布时间】: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