[英]Firebase Cloud Functions Deployement Error
While deploying my codes with firebase functions, I get an error as below.在使用 firebase 函数部署我的代码时,我收到如下错误。 I am getting the error in both functions.我在这两个函数中都遇到了错误。 I think the error is related to the crypto-ts library.我认为该错误与 crypto-ts 库有关。 It would be great if you could help.如果您能提供帮助,那就太好了。 My app is an end-to-end encrypted messaging app.我的应用程序是一个端到端的加密消息应用程序。
My Typescript Codes:我的 Typescript 代码:
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import * as crypto from 'crypto-ts';
admin.initializeApp(functions.config());
const db = admin.firestore();
exports.checkLostMessage = functions.firestore.document("conversations/{conversationId}/messages/{messageId}").onCreate(async (snapshot, context) => {
const data = snapshot.data();
const messageId = snapshot.id;
const { conversationId } = context.params;
const messageData = data['data'];
const jsonString = crypto.AES.decrypt(messageData, messageId).toString(crypto.enc.Utf8);
const messageMap = JSON.parse(jsonString);
if(messageMap['type'] === "lostMessage"){
setTimeout(async function(){
await db.collection("conversations").doc(conversationId).collection("messages").doc(messageId).delete();
} , 15000);
}
})
exports.sendNotifications = functions.firestore
.document('conversations/{conversationId}/messages/{messageId}')
.onCreate(async (snapshot, context) => {
const { message, senderId} = snapshot.data();
const messageId = snapshot.id;
const { conversationId } = context.params;
const conversation = await db
.collection('conversations')
.doc(conversationId)
.get();
const members : string[] = conversation.get('members');
members
.filter((member) => member !== senderId)
.map(async (member) => {
const profile = await db.collection('users').doc(member).get();
const token = profile.get('token');
const jsonString = crypto.AES.decrypt(message, messageId).toString(crypto.enc.Utf8);
const data = JSON.parse(jsonString);
if (!token) {
return;
}
await admin.messaging().sendToDevice(token, {
data: {
conversationId,
userId: member,
senderId,
},
notification: {
title: 'Sohbet - Yeni bir mesajınız var.',
body: data.message,
clickAction: 'FLUTTER_NOTIFICATION_CLICK',
},
});
});
});
My Logs:我的日志:
! functions: package.json indicates an outdated version of firebase-functions.
Please upgrade using npm install --save firebase-functions@latest in your functions directory.
=== Deploying to 'sohbetapp-1339e'...
i deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions@ lint D:\yedekler\sohbetapp\functions
> eslint "src/**/*"
Running command: npm --prefix "$RESOURCE_DIR" run build
> functions@ build D:\yedekler\sohbetapp\functions
> tsc
+ 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 (45.98 KB) for uploading
+ functions: functions folder uploaded successfully
i functions: updating Node.js 12 function checkLostMessage(us-central1)...
i functions: updating Node.js 12 function sendNotifications(us-central1)...
! functions[sendNotifications(us-central1)]: Deployment error.
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.
! functions[checkLostMessage(us-central1)]: Deployment error.
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.
Functions deploy had errors with the following functions:
checkLostMessage
sendNotifications
To try redeploying those functions, run:
firebase deploy --only "functions:checkLostMessage,functions:sendNotifications"
To continue deploying other features (such as database), run:
firebase deploy --except functions
My package.json file content:我的package.json文件内容:
{
"name": "functions",
"scripts": {
"lint": "eslint \"src/**/*\"",
"build": "tsc",
"serve": "npm run build && firebase emulators:start --only functions",
"shell": "npm run build && firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "12"
},
"main": "lib/index.js",
"dependencies": {
"firebase-admin": "^9.2.0",
"firebase-functions": "^3.11.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^3.9.1",
"@typescript-eslint/parser": "^3.8.0",
"eslint": "^7.6.0",
"eslint-plugin-import": "^2.22.0",
"typescript": "^3.8.0",
"firebase-functions-test": "^0.2.0"
},
"private": true
}
My Functions Folder:我的函数文件夹:
I think the source of the error is due to the crypto-ts plugin.我认为错误的根源是由于 crypto-ts 插件。 I need help.我需要帮助。
Seeing your package.json
file, it seems that you haven't installed the crypto-ts
package.看到您的package.json
文件,您似乎还没有安装crypto-ts
package。 We should see it under dependencies
.我们应该在dependencies
下看到它。
Do npm install --save crypto-ts
in your functions
directory.在您的functions
目录中执行npm install --save crypto-ts
。
In addition, note what is indicated in the first lines of the log.此外,请注意日志第一行中指示的内容。 functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory
functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory
. functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.