I'm trying to send an email through an Netlify Lambda, the lambda works smoothly without the Mailjet integration and I've tried the Mailjet integration in a node test script
const { MJ_USER, MJ_PASSWORD } = process.env;
const mailjet = require('node-mailjet').connect(MJ_USER, MJ_PASSWORD)
exports.handler = async (event, context) => {
if (event.httpMethod !== "POST") {
return { statusCode: 405, body: "Method Not Allowed" };
}
const data = JSON.parse(event.body)
const msg = { "Messages":[
{
"From": {
"Email": "sender@gmail.com",
"Name": "Paul"
},
"To": [
{
"Email": "receiver@gmail.com",
"Name": "Emma"
}
],
"TemplateID": 511035,
"TemplateLanguage": true,
"Subject": "Test mail",
"Variables": {
"input": "Test"
}
}
]}
mailjet.post("send", {'version': 'v3.1'}).request(msg)
.then((result) => {
return{ statusCode: 200, body: result.body}
}).catch((err) => {
return err
})
}
Resulting in
{"errorMessage":"i is not a function","errorType":"TypeError","stackTrace":["n (/var/task/hello.js:1:220)","/var/task/hello.js:1:1019","Object.<anonymous> (/var/task/hello.js:1:1030)","Module._compile (module.js:652:30)","Object.Module._extensions..js (module.js:663:10)","Module.load (module.js:565:32)","tryModuleLoad (module.js:505:12)","Function.Module._load (module.js:497:3)","Module.require (module.js:596:17)"]}
The module doesn't appear to load properly but I cannot find a workaround
Update :
I've found more log in Netlify :
2:27:00 PM: Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
2:27:00 PM: @ /opt/build/repo/node_modules/formidable/lib/index.js
2:27:00 PM: @ /opt/build/repo/node_modules/superagent/lib/node/index.js
2:27:00 PM: @ /opt/build/repo/node_modules/node-mailjet/mailjet-client.js
2:27:00 PM: @ /opt/build/repo/node_modules/node-mailjet/index.js
2:27:00 PM: @ ./hello.js