Support `.mjs` output [also a TypeScript issue]
See original GitHub issueI guess we are kind of being forced a little here but someone has to be the bigger guy here 😃
Can you please make it possible to plug into node’s new mjs ESMLoader workflow?
There is a TypeScript issue open already.
Some notes:
must runnode --experimental-modules something.mjs(yes mjs)No longer the case, but
.mjsis always reserved forESM.that--experimental-moduleswill go away obviously.It did but more
--experimental-related flags still linger.- that kicks in a new layer of loaders in node’s internals that completely do not honour conventional require hooks I know you must have hit that already.
Support for
ESMuses a new subsystem that handles allimportoperations. we can’t really force it on non-mjs, unless we get the nodejs team is willing to open things a little.No longer the case, now
package.jsonsupports{ "type": "module" }… etc.- TypeScript already supports “commonjs” as a module, maybe “mjs” too. But it seems they might be recommending
npm install renamer -gthenrenamer -regex --find '\.js^' --replace '.mjs' './outDir/**/*.js'as a solid contribution to making things just work.Can’t speak to this because I no longer transpile from TS as much.
- not sure how well source maps work yet, but that will be a next step on everyone’s agenda.
Not sure how well sourcemaps are handled by native
ESMimplementations. - Some nonstandard ways exist to import/export in .js files (@std/esm and babel) but they are shredded into commonjs on demand.
Native support for
ESMis not as open yet. You can transpile inline and produce standard-compliant javascript that does not get shredded into commonjs, as long as you can name it mjs.See above!
- You are exceptionally positioned to make a difference here.
And people want to help if they can (ie know where they would)
Further references:
- Good discussion points on nodejs PR to Allow runMain to be ESM #14369
- ECMAScript Modules in nodejs api docs.
- Related and recently indexed files in nodejs repo.
- ModuleWrap in internal/loader but seems to expose
{ ModuleWrap } = process.bindings('module_wrap')so not really internal “no-touch” but not officially supported and can break.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:7
- Comments:26 (1 by maintainers)

Top Related StackOverflow Question
I recently implemented and released experimental ESM support. Feedback is being tracked in #1007. Please take it for a spin and let us know if it works.
@blakeembrey… thank you for leaving this open all this time.
<div align=center>🎉
This meant a lot to me personally — thanks!
</div>QIs there a roadmap for this, ie a place for others in the extended community to know where they may contribute towards this goal?