TypeScript is almost always written using modern
import syntax, but you can choose to either transform to CommonJS or use node's native ESM support. Configuration is different for each.
Here is a brief comparison of the two.
|CommonJS||Native ECMAScript modules|
|Write native ||Write native |
|Transforms ||Does not transform |
|Node executes scripts using the classic CommonJS loader||Node executes scripts using the new ESM loader|
|Use any of:||Must use the ESM loader via:|
If you must keep
"module": "ESNext" for
tsc, webpack, or another build tool, you can set an override for
Node's ESM loader hooks are experimental and subject to change.
ts-node's ESM support is also experimental. They may have
breaking changes in minor and patch releases and are not recommended for production.
For complete usage, limitations, and to provide feedback, see #1007.