【发布时间】:2018-03-23 14:49:03
【问题描述】:
我想将新的 Cloud Firestore 集成到我的 Cloud Functions 中。
我更新了 node.js 并在我的 mac 上安装了最新的 firebase 版本。
文档说:
exports.myFunctionName = functions.firestore
.document('users/marie').onWrite((event) => {
// ... Your code here
});
应该可以。我只是复制代码并将其粘贴到 index.js 中,就像所有其他实时数据库函数一样。当我部署函数代码($firebase deploy --only 函数)时,我收到此错误:
Cannot read property 'document' of undefined
at Object.<anonymous> (/private/var/folders/zm/wp2415l929s472jv7kzbt3km0000gn/T/fbfn_21520Y4xqAJosBNHe/index.js:196:45)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
对这个问题有什么建议/想法吗?
【问题讨论】:
-
您的项目中有什么版本的
firebase-functions?您应该将其升级到最新版本,因为 Cloud Firestore 刚刚发布。 -
您可能使用的是旧版本的 SDK。通过在项目的函数目录中运行
npm install firebase-functions@latest --save将其更新为 described in the documentation -
已经这样做了,但我又试了一次。重新启动了我的mac,但仍然是同样的错误
-
我必须更改我的 package.json 才能使其正常工作。
-
@J.Doe。你到底改变了什么?
标签: node.js firebase google-cloud-functions google-cloud-firestore