question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enhancement: Support .mjs & .cjs extensions

See original GitHub issue

Supersedes #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:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:27 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
snoackcommented, May 27, 2020

@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.

2reactions
Haringatcommented, Mar 10, 2020

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found