jsx-email: Can't run a script with ts-node that calls the render function
- Component or Package Name: @jsx-email/all
- Component or Package Version: 3.0.1
@jsx-email/cliVersion?: 3.0.1- Operating System (or Browser): ubuntu
- Node Version:20.0.7
- Link to reproduction (⚠️ read below): https://github.com/co-sic/node-playground
Expected Behavior
I should be able to run the script
Actual Behavior
I get an error:
var import_shikiji = require("shikiji");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/[*****]/node-playground/node_modules/shikiji/dist/index.mjs not supported.
Instead change the require of /home/[*****]/node-playground/node_modules/shikiji/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/home/[*****]/node-playground/node_modules/@jsx-email/code/dist/index.js:42:22)
at require.extensions.<computed> [as .js] (/home/[*****]/node-playground/node_modules/ts-node/dist/index.js:851:20)
at Object.<anonymous> (/home/[*****]/node-playground/node_modules/@jsx-email/all/dist/index.js:22:25)
at require.extensions.<computed> [as .js] (/home/[*****]/node-playground/node_modules/ts-node/dist/index.js:851:20)
at Object.<anonymous> (/home/[*****]/node-playground/src/templates/template.tsx:8:15)
at m._compile (/home/[*****]/node-playground/node_modules/ts-node/dist/index.js:857:29)
at require.extensions.<computed> [as .tsx] (/home/[*****]/node-playground/node_modules/ts-node/dist/index.js:859:16)
at Object.<anonymous> (/home/[*****]/node-playground/src/script.tsx:7:20)
at m._compile (/home/[*****]/node-playground/node_modules/ts-node/dist/index.js:857:29)
at require.extensions.<computed> [as .tsx] (/home/[*****]/node-playground/node_modules/ts-node/dist/index.js:859:16)
at phase4 (/home/[*****]/node-playground/node_modules/ts-node/dist/bin.js:466:20)
at bootstrap (/home/[*****]/node-playground/node_modules/ts-node/dist/bin.js:54:12)
at main (/home/[*****]/node-playground/node_modules/ts-node/dist/bin.js:33:12)
at Object.<anonymous> (/home/[*****]/node-playground/node_modules/ts-node/dist/bin.js:579:5) {
code: 'ERR_REQUIRE_ESM'
}
error Command failed with exit code 1.
Additional Information
It runs no problem with v2.0.0 of jsx-email/all
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 16 (16 by maintainers)
Awesome. We’ll add this to the FAQ on the docs
Jest is well-known to do weird things under the covers, like futzing with
requireto enable import mocks. This https://github.com/jestjs/jest/issues/10944 looks like the same error you’re running into. I’d highly recommend ditching Jest for Vitest (that’s what we use here), but that might be too big a lift.My efforts on the single package are getting closer to done, and you can try that out by installing
jsx-email@nextright now. However, I am using dynamic imports (e.g.await import(...)) there too. If Jest has issues with that, I’m not sure there’s anything that can be done.My guess would be by end of week. We’ll see how work and kids and stuff plays out. I’d recommend the individual packages approach bc it’s newer stuff and capability that will be in the monopackage.