我有一个简单的方法,比如
exports.updatePlayer = functions.firestore
.document('matches/{docId}')
.onCreate((change, context) => {
console.log('fired------------', context.params.docId);
});如果我将一个新文档添加到matches,我可以在日志中看到控制台消息。
问题是我如何在本地运行它?我在package.json里有这个命令
"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.
我想在本地运行这个触发器,这样就可以快速编写/测试我的代码。
发布于 2020-05-23 00:49:40
尝试更新您的NodeJs版本
Firebase宣布在云函数上弃用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运行时
https://stackoverflow.com/questions/61549003
复制相似问题