Skip to content

ERR_REQUIRE_ESM from esm.mjs #1820

Answered by cspotcode
dyllan-to-you asked this question in Q&A
Discussion options

You must be logged in to vote

node -r ts-node/esm is the mistake. Our docs explain correct usage: https://typestrong.org/ts-node/docs/imports

-r ts-node/esm tells node to require ts-node/esm which points to node_modules/ts-node/esm.mjs. esm.mjs is an ESM module and cannot be required, which is why you get that error. It was a fair guess to think dist/esm might be related, but in this case it is not.

Aside from that, ts-node/esm is a node ESM loader so must be used with --loader, not -r.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cspotcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants