mjml: TypeError: Cannot read property 'replace' of undefined

Describe the bug After install the package with the command npm install -g mjml, and run a simple file only with mj-section mj-column mj-text, the following error show:

➜  mjml index.mjml
File: index.mjml
TypeError: Cannot read property 'replace' of undefined

Command line error:
Input file(s) failed to render

PS: the version of mjml 4.7.1 is working.

To Reproduce Steps to reproduce the behavior:

  1. With node version 12.19.0 and npm version 6.14.8 install globally the mjml npm install -g mjml.
  2. Create a file with this MJML code:
<mj-section>
    <mj-column>
        <mj-text> Some text </mj-text>
    </mj-column>
</mj-section>
  1. Render it to HTML by running: mjml index.mjml
  2. See error

Expected behavior A clear and concise description of what you expected to happen.

MJML environment (please complete the following information):

  • OS: MacOS Catalina 10.15.7
  • MJML Version 4.8.2
  • MJML tool used: MJML CLI

Email sending environment(for rendering issues):

  • Platform used to send the email [e.g Putsmail]

Affected email clients (for rendering issues):

  • Email Client [e.g Gmail]
  • OS: [e.g. Windows]
  • Browser [e.g. Google Chrome]

Screenshots If applicable, add screenshots to help explain your problem.

image

Additional context Add any other context about the problem here.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Hi, i think it’s related to the fact that there is no <mjml> and <mj-body> tags in your mjml

Sorry folks, looks like this was user error. After to speaking to another dev on our team we realised that I was using fs.readFileSync to ingest the MJML file, but I wasn’t specifying an encoding, so it was returning an object, not a string.

This was broken:

const data = fs.readFileSync(filePath);
const HtmlBody = mjml2html(data, mjmlOptions);

This worked:

const data = fs.readFileSync(filePath, { encoding: "utf8" }); // added encoding option
const HtmlBody = mjml2html(data, mjmlOptions);

cc @kmcb777 We might need to handle this behavior in MJML5 where rendering without any dep registered would crash because of empty content returned by processing method