0

I am trying to use node-mailjet package

And when i am importing as they show in their documentation, i end up with an error that blocks the production deployment

here are the import lines :

const mailjet = require("node-mailjet").connect(
  settings.mailjet.apiPublicKey,
  settings.mailjet.apiPrivateKey
);

When i do run my webpacks in order to generate my production version i do encounter this error :

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

I am stuck with this

Thanks for your help

1 Answers1

0

Sending mail using Mail Jet

Inside the .env file, set the following fields

.env

MAILJET_PUBLIC_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
MAILJET_SECRET_KEY='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

index.js

const dotenv = require('dotenv');
dotenv.config();

const mailjet = require ('node-mailjet')
.connect(process.env.MAILJET_PUBLIC_KEY, process.env.MAILJET_SECRET_KEY)
const request = mailjet
.post("send", {'version': 'v3.1'})
.request({
  "Messages":[
    {
      "From": {
        "Email": "from@example.com",
        "Name": "from"
      },
      "To": [
        {
          "Email": "to@example.com",
          "Name": "to"
        }
      ],
      "Subject": "Greetings from Mailjet.",
      "TextPart": "My first Mailjet email",
      "HTMLPart": "<h3>Dear passenger 1, welcome to <a href='https://www.mailjet.com/'>Mailjet</a>!</h3><br />May the delivery force be with you!",
      "CustomID": "AppGettingStartedTest"
    }
  ]
})
request
  .then((result) => {
    console.log(result.body)
  })
  .catch((err) => {
    console.log(err.statusCode)
  })
Suresh Mangs
  • 705
  • 8
  • 19