Mjml: require('mjml') is no longer exporting mjml2html as default method

Created on 16 Oct 2018  Â·  12Comments  Â·  Source: mjmlio/mjml

When importing mjml as a node module the method mjml2html is no longer available as default export. This problem occurs since the 4.2 release.

Steps to reproduce the behavior:

  1. Import mjml in a node project using require('mjml')
  2. Convert a template String by calling mjml(templateString, cfg)
  3. Error message mjml is not a function

Expected behavior
The given mjml templateString is converted to html.

MJML environment (please complete the following information):

  • Node 10.11, npm 6.4.1
  • MJML V4.2.0

The new export for handleMjmlConfig seems to be causing this problem: https://github.com/mjmlio/mjml/blob/master/packages/mjml/src/index.js#L49-L51

A workaround to fix this issue on the user's side is explicitly importing the default property: require('mjml').default

Engine

Most helpful comment

I'm not sure how this is fixed. At least in TypeScript, I cannot do either of these:

import mjml2html from "mjml";
import * as mjml2html from "mjml";

The only way to make this work is:

const mjml2html = require("mjml"); // tslint:disable-line no-var-requires

Which is.. undesirable. What is the plan for this?

All 12 comments

Yep I think we no longer want export anything else than the mjml2html function into mjml package. Removing this export should be fine, mjml-app might need some update due to this change cc @kmcb777

Should I still make a pull request? I removed the export for handleMjmlConfig in my local fork and it seems to be working as expected.

We've discussed a bit and it was used in mjml-app, so we might need to check that it works fine with the app first

@Michael-wm kudos to you for creating this issue.

The babel-plugin-add-module-exports export the default when only have one default export. The mjml package is breaked (in a minor version) since that the handleMjmlConfig is exposed in the same file.

EDIT: It's fixed, I did not see.

I'm not sure how this is fixed. At least in TypeScript, I cannot do either of these:

import mjml2html from "mjml";
import * as mjml2html from "mjml";

The only way to make this work is:

const mjml2html = require("mjml"); // tslint:disable-line no-var-requires

Which is.. undesirable. What is the plan for this?

I'm not a TS user so I don't really know why import mjml2html from "mjml";, but it should work fine 🤔

So the default is no longer needed, I'm closing the issue.

About the typescript issue, feel free to investigate a bit (maybe it comes from our babel config) and open a new issue please.

I'm still having this problem =/

You need to add some details, node version, mjml packages version, etc...
we can't really guess what's the issue for you ?

On Wed, Dec 26, 2018 at 6:34 PM Luan Muniz notifications@github.com wrote:

I'm still having this problem =/

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/mjmlio/mjml/issues/1387#issuecomment-449998487, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAizzVV8TvmUgR4JPL-OPfCS4PJjz6J-ks5u87MOgaJpZM4Xd2RD
.

--
Cordialement,
Maxime BRAZEILLES

It's not the same problem. I will create another issue for it. Sorry

Hi, this is likely not related to mjml directly, it's probably related to how you're building your code
If you import any other node module at this same place, you should have the same error

Was this page helpful?
0 / 5 - 0 ratings

Related issues

csmcanarney picture csmcanarney  Â·  3Comments

liminspace picture liminspace  Â·  3Comments

iwanaga-sakura picture iwanaga-sakura  Â·  4Comments

lucasnantonio picture lucasnantonio  Â·  4Comments

valstu picture valstu  Â·  3Comments