简体   繁体   English

Firebase 云函数:require('nodemailer') 导致错误

[英]Firebase Cloud Functions: require('nodemailer') causes error

I am trying to add email to a firebase cloud function.我正在尝试将 email 添加到 firebase 云 function 中。 However, when ever I add the line:但是,每当我添加该行时:

const nodemailer = require('nodemailer'); 

to index.js, code which previously deployed will no longer deploy.到 index.js,之前部署的代码将不再部署。 It reports that one of my functions had an error, but this can't be the case cause it works just fine with that function.它报告我的一个函数有错误,但事实并非如此,因为它与 function 配合得很好。 Here is the full code, runs without the line just fine.这是完整的代码,没有行就可以了。

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
admin.initializeApp();


exports.routineKick = functions.pubsub
  .schedule('every 2 minutes')
  .timeZone('America/New_York')
  .onRun(context => {
     //kickMembers();
  }
);

Posting the solution as a Community Wiki since this solution was shared by an edit to the question itself by the OP.将解决方案发布为社区 Wiki,因为此解决方案是由 OP 对问题本身的编辑共享的。

The problem is that the app was missing the nodemailer dependency.问题是该应用程序缺少 nodemailer 依赖项。 It can be fixed by doing the following:可以通过执行以下操作来修复它:

In the package.JSON file, located at the functions folder, add under dependencies the following: "nodemailer": "^6.4.3" or whatever version you have.在位于函数文件夹的 package.JSON 文件中,在dependencies项下添加以下内容: "nodemailer": "^6.4.3"或您拥有的任何版本。

I'm using node mailer version of 6.7.0, In the "package.JSON" file, downgrade node version from 14 to 10 works for me我正在使用 6.7.0 的节点邮件程序版本,在“package.JSON”文件中,将节点版本从 14 降级到 10 对我有用

"engines": {
"node": "10"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"nodemailer": "^6.7.0"
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM