Enhancement: Support .mjs & .cjs extensions
See original GitHub issueSupersedes #50 & #59 - Please see them for additional context
We currently have support for ESModules using the .esm.js
extension and the esm
module to transpile them on the fly. However, node 13 (and the upcoming 14) support the .mjs
and .cjs
extensions. I’ve run into a bunch of troubles reviewing, interpreting, and testing those features, but I’d like to support them.
I’d love some help here @ulrichb @cedx or anyone else with experience.
One other note: I believe this will be a breaking change because it seems the .cjs
extension can’t be used outside a .mjs
instance.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:27 (10 by maintainers)
Top Results From Across the Web
ECMAScript modules | Node.js v19.3.0 Documentation
Node.js fully supports ECMAScript modules as they are currently specified and ... Node.js to use the ECMAScript modules loader via the .mjs file...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
Node.js supports two extensions to help with this: .mjs and .cjs . .mjs files are always ES modules, and .cjs files are always...
Read more >pkgroll - npm
pkgroll. Write your code in ESM & TypeScript and bundle it to get ESM, CommonJS, and type declaration outputs with a single command!...
Read more >Hybrid npm packages (ESM and CommonJS) - 2ality
In this blog post, we look at npm packages that contain both ES modules and CommonJS modules.
Read more >CJS vs ESM - Andrea Giammarchi - Medium
That's how pointless any file name, or extension, could be, and yet the whole CJS module system trusts this is the way to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@phated I had a go. It’s still WIP, but I could already use some feedback. BTW, it seems I found a way to keep things backwards-compatible all the way back to Node.js 0.10.
@yannbf That attempt still relies on a transpiler (in this case babel) to work. We can already do that using the esm package. What this issue is about, however, is leveraging Node’s native support for esm modules so that no transpiler is necessary.