簡體   English   中英

Firebase 雲函數部署錯誤

[英]Firebase Cloud Functions Deployement Error

在使用 firebase 函數部署我的代碼時,我收到如下錯誤。 我在這兩個函數中都遇到了錯誤。 我認為該錯誤與 crypto-ts 庫有關。 如果您能提供幫助,那就太好了。 我的應用程序是一個端到端的加密消息應用程序。

我的 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',
          },
        });
      });
  });

我的日志:

!  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

我的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
}

我的函數文件夾:

在此處輸入圖像描述

我認為錯誤的根源是由於 crypto-ts 插件。 我需要幫助。

看到您的package.json文件,您似乎還沒有安裝crypto-ts package。 我們應該在dependencies下看到它。

在您的functions目錄中執行npm install --save crypto-ts


此外,請注意日志第一行中指示的內容。 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM