Florian
Florian

Reputation: 266

Deployment Error deploying Cloud Function with Firebase Trigger

I am trying to create a Cloud function which sends a firebase cloud message to the users when a new document is created. Somehow I can not deploy the function to Firebase.

Here is my index.js:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp(functions.config().firebase);

exports.sendAll = functions.region("europe-west3").firestore
    .document("NewsCard/{docId}")
    .onCreate((snapshot) => {
      const title = snapshot.get("Title");
      const subject = snapshot.get("Text");

      const payload = {
        notification: {
          title: title,
          body: subject,
          sound: "default",
        },
      };

      return admin.messaging().sendToTopic("Announcement", payload);
    });

This is the error I get when I type firebase deploy:

✔  functions: Finished running predeploy script.
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (64.26 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 12 function sendAll(europe-west3)...
⚠  functions[sendAll(europe-west3)]: Deployment error.
...
Error: Functions did not deploy properly.

What is causing this problem? I read somewhere on the internet, that the firestore path .document("NewsCard/{docId}") could be wrong. But I dont know what to use instead.

Here is my Firestore: Firestore

Upvotes: 0

Views: 267

Answers (1)

Florian
Florian

Reputation: 266

Figured it out myself. Seems to be a problem with Node. See #3120 for more information. Downgrade Node to 14 helps.

Upvotes: 1

Related Questions