question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'replace' of undefined

See original GitHub issue

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.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kmcb777commented, Apr 1, 2021

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

1reaction
garrettccommented, Mar 10, 2021

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);
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'replace' of Undefined in JS
The "Cannot read property 'replace' of undefined" error occurs when calling the replace() method on a variable that stores an undefined value. To...
Read more >
Cannot read property 'replace' of Undefined in JS - Isotropic
Cannot read property 'replace' of Undefined in JS ... method such as TypeError: Cannot read properties of undefined (reading 'replace') .
Read more >
cannot read property 'replace' of undefined In Grid - Stack ...
I think jQuery cannot find the element. First of all find the element var rowTemplate= document.getElementsByName("rowTemplate");.
Read more >
TypeError: Cannot read property 'replace' of undefined
So I tried to learn how to do this on my own by taking two video courses about node and cheerio on udemy...
Read more >
Error: Cannot read property 'replace' of undefined #649 - GitHub
Actual behaviour error Error: Evaluation failed: TypeError: Cannot read property 'replace' of undefined at Object.processFormControls...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found