Skip to content

Docs mention of setting "type" to "module" in Package.json #1429

Answered by drwpow
StepanMynarik asked this question in Q&A
Discussion options

You must be logged in to vote

That enables ECMAScript modules (ESM) in Node (import / export). ESM is the new universal standard for JS and works in Node and the browser. By default, Node still uses CommonJS (CJS) (require()) for backwards compatibility, but is being phased out. Other projects like Deno also rely on ESM.

I won’t go into the details of ESM and the whole history, but it’s been chosen as the standard because it’s statically-analyzable (an essential for the web so imports can be fetched after the parsing phase rather the execution phase, resulting in a drastic speedup) and allows easier tree-shaking.

If you’re writing client code you should always use ESM (because that’s what the browser expects). If only…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@StepanMynarik
Comment options

@drwpow
Comment options

@StepanMynarik
Comment options

Answer selected by StepanMynarik
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