mjmlio / mjml

MJML: the only framework that makes responsive-email easy
https://mjml.io
MIT License
17.08k stars 960 forks source link

mjml2html is not a function #959

Closed ruudboon closed 6 years ago

ruudboon commented 6 years ago

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?

iRyusa commented 6 years ago

Hello,

We no longer expose a class, so the export default is now mjml2html function, removing those brackets will fix it

On Sat, Jan 20, 2018 at 11:09 AM, Ruud Boon notifications@github.com wrote:

When trying out MJML4 with the node example provided

import { mjml2html } from 'mjml'

/ Compile an mjml string / const htmlOutput = mjml2html(`

Hello World!

`)

/ 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?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mjmlio/mjml/issues/959, or mute the thread https://github.com/notifications/unsubscribe-auth/AAizzSBKASUZEim8fpf48UkmfODJZsZhks5tMbtCgaJpZM4RlYjA .

-- Cordialement, Maxime BRAZEILLES

ruudboon commented 6 years ago
const htmlOutput = mjml_1.default(`
TypeError: mjml_1.default is not a function

Gives undefined. I'll will check the code to see what's happening. btw I'm on 4.0.0-alpha.5.

iRyusa commented 6 years ago

Well it should work with the regular import of mjml package, we'll investigate

On 21 Jan 2018, at 08:45, Ruud Boon notifications@github.com wrote:

Ah, importing mjml-core instead of miml works way better..Want me to sent a pull for the documentation?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

ngarnier commented 6 years ago

@ruudboon can you try just replacing

import { mjml2html } from 'mjml'

by

import mjml2html from 'mjml'

I tried and it works fine

iRyusa commented 6 years ago

Well as @ngarnier said, it works for me too, might be an issue with your babel config, I'm closing the issue.

You can try it back with the latest beta to see if it fix it for you

ruudboon commented 6 years ago

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

import * as mjml2html from 'mjml'
timc13 commented 6 years ago

how would this work with gulp-mjml ?

crabmusket commented 6 years ago

The current master branch of gulp-mjml has a fix for this issue. I've installed it like so in package.json:

    "gulp-mjml": "git+https://git@github.com/mjmlio/gulp-mjml.git#1cf5074c32621a2d6bc7",
iRyusa commented 6 years ago

It has been released on npm too so no need to use the git package 👌

crabmusket commented 6 years ago

Oh great, not sure why I didn't realise that!

wanoo21 commented 6 years ago

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

import mjml2html = require('mjml');

It works very well with typescript!

marpstar commented 6 years ago

FWIW, I had to use

import mjml2html from "mjml";

with the allowSyntheticDefaultImports property of my tsconfig.json set to true

rmagon commented 4 years ago

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

notflip commented 2 years ago

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

AlexAntonyan commented 1 year ago

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.

danielpizarrotadres commented 10 months ago

Hi ! I'm having this error when i try to mock the function using Jest.

How could i mock the mjml2mjml function importing: import * as mjml2html from 'mjml' ?

Matthiasc commented 1 month ago

I am having great issues using it on Netlify functions (and I think it might be a Netlify related thing really)

TypeError: (0 , import_mjml_core.default) is not a function

I had to the following as the only thing that would work:

import * as mjml2html from "mjml";
mjml2html.default(`<mjml>....)