调用Firebase Function会引发错误-错误TypeError:Gb.functions不是函数

时间:2020-08-13 21:04:12

标签: angular firebase google-cloud-functions

我最近刚刚开始使用Firebase Functions,希望在运行NG Build --Prod之后收到以下错误消息的帮助:

错误类型错误:Gb.functions不是函数

此错误消息非常奇怪的是,我在本地主机上没有收到该消息,并且在运行NG Serve --Open时可以无错误地调用firebase函数。

当我单击“测试”按钮时,我希望将电子邮件发送到我的收件箱中。

您能提供的任何见解将不胜感激!

谢谢

<!-- begin snippet: js hide: false console: true babel: false -->
<button (click)="test()">Test</button>

const functions = require('firebase-functions');
const nodemailer = require("nodemailer");
const express = require("express");
const app = express();
const admin = require('firebase-admin');
const cors = require('cors')({ origin: true });
admin.initializeApp();


let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'xxx',
        pass: 'xxx'
    }
});

exports.sendMail = functions.https.onRequest((req, res) => {
    cors(req, res, () => {

        // getting dest email by query string
        const dest = req.query.dest;

        const mailOptions = {
            from: 'xxx', // Something like: Jane Doe <janedoe@gmail.com>
            to: 'xxx',
            subject: 'test', // email subject
            html: `test` 
        };

        // returning result
        return transporter.sendMail(mailOptions, (error, info) => {
            if (error) {
                return res.send(error.toString());
            }
            return res.send('Sended');
        });
    });
});

test() {
    const helloWorld = firebase.functions().httpsCallable('sendMail');
    helloWorld().then((result) => {
      console.log(result.data.output);
    }).catch((error) => {
      console.log(`error occurred`);
    });
  }

0 个答案:

没有答案