使用Firebase触发器部署云功能时发生部署错误 [英] Deployment Error deploying Cloud Function with Firebase Trigger
问题描述
我正在尝试创建一个Cloud函数,该函数在创建新文档时将Firebase云消息发送给用户.我无法以某种方式将功能部署到Firebase.
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.
这是我的index.js:
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);
});
这是我输入 firebase deploy
时遇到的错误:
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.
是什么导致此问题?我在互联网上的某个地方读到,firestore路径 .document("NewsCard/{docId}")
可能是错误的.但是我不知道该用什么.
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.
这是我的Firestore:
Here is my Firestore:
推荐答案
自己弄清楚了.似乎是Node的问题.有关更多信息,请参见#3120 .将Node降级到14个可以帮助您.
Figured it out myself. Seems to be a problem with Node. See #3120 for more information. Downgrade Node to 14 helps.
这篇关于使用Firebase触发器部署云功能时发生部署错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!