mjml: mjml2html is not a function

When trying out MJML4 with the node example provided

import { mjml2html } from 'mjml'

/*
  Compile an mjml string
*/
const htmlOutput = mjml2html(`
  <mjml>
    <mj-body>
      <mj-section>
        <mj-column>
          <mj-text>
            Hello World!
          </mj-text>
        </mj-column>
      </mj-section>
    </mj-body>
  </mjml>
`)

/*
  Print the responsive HTML generated and MJML errors if any
*/
console.log(htmlOutput)

I get the following message:

const htmlOutput = mjml_1.mjml2html(`
TypeError: mjml_1.mjml2html is not a function

Is the naming changed?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

Sorry my fault indeed. It was part of a typescript project so I had to do

import * as mjml2html from 'mjml'

I also had this issue, and I found this solution.

import mjml2html = require('mjml');

It works very well with typescript!

I resolved the issue by importing it like this: import mjml2html from 'mjml';, and I added the esModuleInterop: true property to the ts.config.json file.

how would this work with gulp-mjml ?

import * as mjml2html from 'mjml' worked for my typescript project 😃 Thank you @ruudboon

It worked but I didn’t have any type support in Webstorm using this method

@ruudboon can you try just replacing

import { mjml2html } from 'mjml'

by

import mjml2html from 'mjml'

I tried and it works fine