将功能部署到Firestore时出错:

时间:2020-08-23 17:56:40

标签: javascript firebase google-cloud-firestore google-cloud-functions

每次将新用户添加到我的Firestore数据库时,我都试图触发电子邮件。以下代码是通过遵循Youtube教程编写的,因为我不熟悉功能部署。下面的代码是在functions / index.js中编写的,但是触发了一个我不确定如何解决的错误:“部署错误。加载用户代码时功能失败。错误消息:错误:请检查功能日志以查看错误原因:https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs'。完整错误可在代码下方找到。 谢谢!

const functions = require("firebase-functions");

const nodemailer = require("nodemailer");

const admin = require("firebase-admin");

admin.initializeApp();

require("dotenv").config();

const { SENDER_EMAIL, SENDER_PASSWORD } = process.env;

exports.sendEmailNotification = functions.firestore
  .document("submissions/{docId}")
  .onCreate((snap, ctx) => {
    const data = snap.data();

    let authData = nodemailer.createTransport({
      host: "smtp.gmail.com",
      port: 465,
      secure: true,
      auth: { user: SENDER_EMAIL, pass: SENDER_PASSWORD },
    });

    authData
      .sendMail({
        from: "developer@chutoro.app",
        to: `${data.email}`,
        subject: `Submssion Accepted`,
        text: `${data.email}`,
      })
      .then((res) => console.log("Successfully sent mail"))
      .catch((err) => console.log(err));
  });
+  functions: Finished running predeploy script.
i  firestore: reading indexes from firestore.indexes.json...
i  cloud.firestore: checking firestore.rules for compilation errors...
!  [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
+  cloud.firestore: rules file firestore.rules compiled successfully
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  firestore: latest version of firestore.rules already up to date, skipping upload...
+  firestore: deployed indexes in firestore.indexes.json successfully
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (40.2 KB) for uploading
+  functions: functions folder uploaded successfully
+  firestore: released rules firestore.rules to cloud.firestore
i  functions: updating Node.js 10 function sendEmailNotification(us-central1)...
!  functions[sendEmailNotification(us-central1)]: Deployment error.
Function failed on loading 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

1 个答案:

答案 0 :(得分:1)

我在依赖项中添加了“ nodemailer”:“ ^ 6.4.11”,现在对我有用