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.

Webpack fails to compile after importing mjml2html

See original GitHub issue

Hey there,

I’m running into an issue using mjml2html in a local Vue CLI 3 project (Vue CLI 3 runs on webpack). I’ve installed mjml - "mjml": "^4.2.0-beta.3" - and I’m importing the function as such - import mjml2html from 'mjml'. Once I’ve imported, my app breaks with the following warnings:

Warnings generated in terminal:

 warning  in ./node_modules/mjml-core/lib/index.js
Critical dependency: the request of a dependency is an expression
 warning  in ./node_modules/mjml-core/lib/helpers/mjmlconfig.js
Critical dependency: the request of a dependency is an expression
 warning  in ./node_modules/mjml-core/lib/helpers/mjmlconfig.js
Critical dependency: the request of a dependency is an expression
 warning  in ./node_modules/mjml-core/lib/helpers/mjmlconfig.js
Critical dependency: the request of a dependency is an expression
 warning  in ./node_modules/uglify-js/tools/node.js
Critical dependency: the request of a dependency is an expression

Warnings/error generated by the browser console:

screen shot 2018-10-05 at 6 26 19 pm

I’ve also tried this using react (create-react-app), and I’m running into the same issue. Is anyone else experiencing this?

Any help would be greatly appreciated.

Reproduction Steps:

  1. Generate a create-react-app, or Vue CLI 3 project
  2. Install mjml - yarn add mjml
  3. Import mjml2html anywhere in the project - import mjml2html from 'mjml'

MJML version:

"mjml": "^4.2.0-beta.3"

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
svengaucommented, Nov 20, 2019

MJML uses html-minifier, which uses uglify-js, and uglify-js is not compatible with Webpack.

Related issue: https://github.com/mishoo/UglifyJS2/issues/3312

[Edit]: And I’ve finally found a workaround, thanks to this post: https://github.com/kangax/html-minifier/issues/727

rules: [
  // ... some rules
  {
    test: path.resolve(__dirname, 'node_modules/uglify-js/tools/node.js'),
    loader: 'null-loader',
  },
  // ...some more rules
]
1reaction
kmcb777commented, Jun 25, 2019

@ShanakaNCG what is your problem exactly ? from what i read here, the problem was that he was trying to import mjml2html on the client side. This is not possible because mjml uses node libs, i.e. fs to handle mj-include. You have to use it server side, if you don’t have a node server you could use the api https://mjml.io/api

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack suddenly fails to compile due to "Module not ...
To do this, we import our webpack config and then plug various values into the Karma webpack config. Building the scripts directly using...
Read more >
Building a Webpack plugin to generate localized emails
After some initial prototyping, we landed on using MJML, ... Webpack will drive compilation and take that React code and data to build...
Read more >
How to use the mjml.mjml2html function in mjml
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
Issue with 4.9.0 + webpack + typescript
I'm not such a webpack specialist, but it seems to me that webpack does not compile node_modules content and this causes later errors....
Read more >
webpack/webpack - Gitter
However, when I wrap it all in a webpack build and use postcss-loader it appears that postcss-loader runs ... webpack serve [webpack-cli] Failed...
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