mjml: Cannot find module '../lib/utils.js' in esbuild
Describe the bug
When importing mjml into an esbuild project the build works fine, but the compiled app has this error:
Error: Cannot find module '../lib/utils.js'
Full trace:
Error: Cannot find module '../lib/utils.js'
Require stack:
- /Users/thom/develop/laboratory/mjml-build-error/out.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
at Function.resolve (node:internal/modules/cjs/helpers:98:19)
at /Users/thom/develop/laboratory/mjml-build-error/out.js:39836:13
at /Users/thom/develop/laboratory/mjml-build-error/out.js:11:5
at /Users/thom/develop/laboratory/mjml-build-error/out.js:39919:18
at /Users/thom/develop/laboratory/mjml-build-error/out.js:11:5
at /Users/thom/develop/laboratory/mjml-build-error/out.js:47259:23
at /Users/thom/develop/laboratory/mjml-build-error/out.js:11:5
at /Users/thom/develop/laboratory/mjml-build-error/out.js:51912:43
at /Users/thom/develop/laboratory/mjml-build-error/out.js:11:5 {
code: 'MODULE_NOT_FOUND',
requireStack: [ '/Users/thom/develop/laboratory/mjml-build-error/out.js' ]
}
To Reproduce I’ve uploaded a very simple working example just follow README to run:
https://drive.google.com/uc?id=1Xfb9d1jEJ9nIOyI8Tqnm6tuRkydRKdb3&export=download
Expected behavior The app should execute without errors.
MJML environment (please complete the following information):
- OS: Mac OS 11.1 Big Sur
- MJML Version 4.8.1
- MJML tool used: npm package
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 18 (4 by maintainers)
Commits related to this issue
- fix: email sending after creation MJML library need uglify-js to be bundled in node_modules. https://github.com/mjmlio/mjml/issues/2132 https://github.com/mjmlio/mjml/issues/2132#issuecomment-11671... — committed to pehtoorismies/downtown65-app by deleted user 2 years ago
- fix: email sending after creation MJML library need uglify-js to be bundled in node_modules. https://github.com/mjmlio/mjml/issues/2132 https://github.com/mjmlio/mjml/issues/2132#issuecomment-11671... — committed to pehtoorismies/downtown65-app by deleted user 2 years ago
Hi I’ve found a workaround inspired by https://github.com/mjmlio/mjml/issues/1365#issuecomment-555835755. Basically, i defined a plugin that would return an empty module for the uglify node file:
tested with mjml 4.11.0
For anyone trying to use MJML in AWS Lambda bundled with CDK (which uses esbuild):
@sadtomatoofjoy workaround cannot be used because CDK doesn’t provide the ability to define custom esbuild plugins (it is used in CLI, not in Node). I got it working by adding
uglify-jsin thenodeModulesproperty.It increases the code size indeed, but it’s the best I found.