-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Support .mjs output #18442
Copy link
Copy link
Closed
Labels
Domain: ES ModulesThe issue relates to import/export style module behaviorThe issue relates to import/export style module behaviorIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Metadata
Metadata
Assignees
Labels
Domain: ES ModulesThe issue relates to import/export style module behaviorThe issue relates to import/export style module behaviorIn DiscussionNot yet reached consensusNot yet reached consensusSuggestionAn idea for TypeScriptAn idea for TypeScript
Experimental support for ES modules just landed in Node 8.5 (changelog, PR).
Since ES modules have some parsing and semantic differences, Node decided to use the
mjsextension for ES modules (whilejsis for the "script" target and commonjs modules).The current Typescript version (
2.5.2) supports ES modules emission but uses thejsextension by default. It means that to use it with Node, a post-compilation step is required to change the extension fromjstomjs. This adds undesirable complexity to use native ES modules support with Node.A solution would be to add a compiler option to output
*.mjsfiles when emitting ES modules.Edit (2018-03-22): The propositions below are a bit outdated. I recommend reading the issue to see the progression. See this comment for my current proposition.
Notes:
*.jsextension, many tools rely on thejsextension.*.mtsfiles would compile to*.mjs, this would be similar to*.tsxand*.jsx.