1

I´m implementing an Serverless stack on AWS with a Lambda function that submits an email formatted with MJML library in HTML format.

When trying to isolate the issue, I´ve created a simple function with the next code that runs on AWS lambda and it on itself doesn´t run (the rest does):

import mjml2html from 'mjml';

export async function sendEmail(){
  console.log("sendEmail reached");
  return mjml2html(`
  <mjml>
  <mj-body>
    <mj-section>
      <mj-column>

        <mj-image width="100px" src="/assets/img/logo-small.png"></mj-image>

        <mj-divider border-color="#F45E43"></mj-divider>

        <mj-text font-size="20px" color="#F45E43" font-family="helvetica">Hello World</mj-text>

      </mj-column>
    </mj-section>
  </mj-body>
</mjml>
`);

Even with this simple function, when calling the AWS lambda, I always get the following error and the console.log() isn´t executing, so I assume the error happens already at the import time:

    "errorType": "TypeError",
    "errorMessage": "Cannot read property '1' of undefined",
    "stack": [
        "TypeError: Cannot read property '1' of undefined",
        "    at isFileType (fs.js:178:19)",
        "    at Object.readFileSync (fs.js:367:16)",
        "    at /var/task/src/handlers/webpack:/uglify-js/tools/node.js:20:19",
        "    at Array.map (<anonymous>)",
        "    at /var/task/src/handlers/webpack:/uglify-js/tools/node.js:19:30",
        "    at Object.7199 (/var/task/src/handlers/webpack:/uglify-js/tools/node.js:24:1)",
        "    at ni (/var/task/src/handlers/webpack:/webpack/bootstrap:19:32)",
        "    at Object.56069 (/var/task/src/handlers/webpack:/html-minifier/src/htmlminifier.js:8:16)",
        "    at ni (/var/task/src/handlers/webpack:/webpack/bootstrap:19:32)",
        "    at Object.1510 (/var/task/src/handlers/webpack:/mjml-core/lib/index.js:100:21)"
    ]
}

I´ve looked for info on the same issue in mjml repo, mjml documentation, this forum... but no luck.

Could anybody help me identify the issue?

Thanks a lot.

Markussen
  • 164
  • 1
  • 13
  • I have exactly the same issue, and after much trial, error, and debugging I've discovered that the issue appears to be with the file system module. I copied all the minified code out of the Lambda, ran it locally using node cli and I received the following error. `node:fs:208 let mode = stats[1]; ^ TypeError: Cannot read properties of undefined (reading '1')` Maybe the module is trying to load an external file from somewhere since MJML tends to be a cli app? No idea. – benanderson89 Aug 04 '22 at 13:58
  • 1
    Turns out it's a known issue: https://github.com/mjmlio/mjml/issues/2173 – benanderson89 Aug 04 '22 at 14:08

0 Answers0