简体   繁体   中英

Firebase Cloud Functions: require('nodemailer') causes error

I am trying to add email to a firebase cloud function. However, when ever I add the line:

const nodemailer = require('nodemailer'); 

to index.js, code which previously deployed will no longer deploy. 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. 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.

The problem is that the app was missing the nodemailer dependency. 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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