Cloud Firestore in Cloud Features

I want to integrate the new Cloud Firestore into my cloud features.

I updated node.js and installed the latest firebase on my mac.

The documentation says:

exports.myFunctionName = functions.firestore .document('users/marie').onWrite((event) => { // ... Your code here }); 

must work. I simply copied the code and entered it in index.js, like all other real-time database functions. When I deploy the function code ($ firebase deploy --only functions), I get this error:

 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) 

Any suggestions / ideas on the issue?

+5
source share
5 answers

Ok, I tried all of this, but it didn't work. But firebase brought out the update, now it works :)

It looks like they had some mistakes.

Thank you for your help!

0
source

Try changing your package to:

 { "name": "functions", "description": "Cloud Functions for Firebase", "dependencies": { "firebase-admin": "~5.4.0", "firebase-functions": "^0.7.0" }, "private": true } 

And start the update after that in the terminal (npm update).

+2
source

Just calling firebase init did it for me. (this also changed the Package.json file)

+2
source

I went through the process of creating a completely new project in a new folder and got rid of this error.

+1
source

As mentioned in firebase-documentation .

In many cases, new features and bug fixes are only available with the latest version of the Firebase CLI and firebase-functions SDK. It is good practice to frequently update the Firebase CLI and SDK using these commands inside the function folder of your Firebase project:

Always make sure you are using updated packages.

 npm install firebase-functions@latest --save npm install -g firebase-tools 
0
source

Source: https://habr.com/ru/post/1272539/


All Articles