Skip to content

Does ts-node support only "module": "CommonJS"? #1794

Answered by cspotcode
PavelTurk asked this question in Q&A
Discussion options

You must be logged in to vote

ts-node supports all module modes, including the new NodeNext. I suspect you forgot to set "type" in your package.json

For you, I recommend using new new NodeNext mode.

To understand better what's going on, I recommend starting here:
https://typestrong.org/ts-node/docs/imports
And to learn about NodeNext, start here:
https://devblogs.microsoft.com/typescript/announcing-typescript-4-7/#esm-nodejs

If you choose not to use NodeNext, your project will still work! But remember that package.json "type" will be important no matter what mode you choose.

Remember, node's ESM support still has rough edges, so care must be taken in project configuration.

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