【问题标题】:Firebase Cloud Functions Deployement ErrorFirebase 云函数部署错误
【发布时间】:2021-05-06 21:49:57
【问题描述】:

在使用 firebase 函数部署我的代码时,我收到如下错误。我在这两个函数中都遇到了错误。我认为该错误与 crypto-ts 库有关。如果您能提供帮助,那就太好了。我的应用是一个端到端的加密消息应用。

我的打字稿代码:

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 插件。我需要帮助。

【问题讨论】:

    标签: javascript node.js typescript firebase google-cloud-functions


    【解决方案1】:

    看到您的package.json 文件,您似乎还没有安装crypto-ts 软件包。我们应该在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.

    【讨论】:

    • 我添加到文件中:''' "dependencies": { "firebase-admin": "^9.2.0", "firebase-functions": "^3.13.1", "crypto- ts" : "^1.0.2" },''' 但我有一个错误:
    • 02T17_18_08_312Z-debug.log;错误 ID:beaf8772 !功能[sendNotifications(us-central1)]:部署错误。构建失败:npm ERR! cipm 只能在您的 package.json 和 package-lock.json 或 npm-shrinkwrap.json 同步时安装包。请在继续之前使用npm install 更新您的锁定文件。 npm 错误! npm 错误! npm 错误!缺少:crypto-ts@^1.0.2 npm 错误! npm 错误!可以在以下位置找到此运行的完整日志:npm ERR! /builder/home/.npm/_logs/2021-02-02T17_18_09_220Z-debug.log;错误 ID:beaf8772
    • “我添加到文件”是什么意思?您不应该手动添加,而是使用 npm install 命令。
    • 谢谢!感谢您,我解决了我的问题
    猜你喜欢
    • 1970-01-01
    • 2020-03-26
    • 2021-12-01
    • 2017-12-12
    • 2018-09-13
    • 1970-01-01
    • 2021-04-10
    • 2018-08-04
    相关资源
    最近更新 更多