I am using MailerSend with Firebase Functions. Since Firebase Functions cannot be used with ES6 I am using V1 of MailerSend's NodeJS SDK. The SDK shows the following code for sending an email.
const Recipient = require("mailersend").Recipient;
const EmailParams = require("mailersend").EmailParams;
const MailerSend = require("mailersend");
const mailersend = new MailerSend({
api_key: "key",
});
const recipients = [
new Recipient("[email protected]", "Your Client")
];
const emailParams = new EmailParams()
.setFrom("[email protected]")
.setFromName("Your Name")
.setRecipients(recipients)
.setReplyTo("[email protected]")
.setReplyToName("Reply to name")
.setSubject("Subject")
.setHtml("This is the HTML content")
.setText("This is the text content");
mailersend.send(emailParams);
I am adding this code to index.js in my Firebase Functions Folder.
functions
-index.js
When I deploy the code to Firebase Functions with the Firebase CLI command below I get an error stating.
Error: Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
firebase deploy --only functions
I ran the debug option on functions shown below and am getting the following.
Got response code 400; body Failed to generate manifest from function source: TypeError: MailerSend is not a constructor shutdown requested via /__/quitquitquit
firebase deploy --only functions --debug
I have not idea why this would be the case. For more clarity I removed as much code from the MailerSend sample above to recreate the error. I have added a simple index.js file where the error occurs and my package.json file.
index.js
const functions = require('firebase-functions')
require('dotenv').config()
const MailerSend = require('mailersend')
const MAILERSEND_API_KEY = process.env.MAILERSEND_API_KEY
const mailersend = new MailerSend({
api_key: MAILERSEND_API_KEY,
})
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"lint": "eslint .",
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "index.js",
"dependencies": {
"@sentry/node": "^7.54.0",
"axios": "^1.5.0",
"dotenv": "^16.3.1",
"firebase-admin": "^11.5.0",
"firebase-functions": "^4.2.0",
"mailersend": "^2.2.0",
"stripe": "^13.7.0"
},
"devDependencies": {
"@sentry/browser": "^7.54.0",
"@sentry/tracing": "^7.54.0",
"eslint": "^8.15.0",
"eslint-config-google": "^0.14.0",
"firebase-functions-test": "^3.0.0"
},
"private": true
}
Any help would be greatly appreciated.