Poor CommonJS experience
See original GitHub issueDescribe the bug
Many projects don’t have the option of switching wholesale over to ESM, and must use CommonJS. This will probably be true for the foreseeable future, as CommonJS will be here to stay for at least five years.
It’s pretty difficult to tease out how to use this package with CommonJS, there are no docs or mention of it anywhere.
The best I can come up with to make it work is something like:
const module = await import('@keycloak/keycloak-admin-client');
const KcAdminClient = module.default.default;
I was only able to figure this out after putting breakpoints on and inspecting the module - it’s strange to have to do .default.default
Is there a way to improve the developer experience with CommonJS?
Version
18.0.0
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Anything else?
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Disadvantage of ES6 and CommonJS export convention
Babel will use module.exports as default export if the imported module is CommonJS, so I don't see how module.exports.default = Struct helps. Do ......
Read more >Annoyed by the schism between CommonJS and ESM - Reddit
The arguments there are all weak. "It is risky" is only true if you use typescript wrong or use weird libraries. Most important...
Read more >Default Exports in JavaScript Modules Are Terrible
In this article, I want to explain why default exports are a poor practice and lead to a worse developer experience. Consider an...
Read more >ES modules are terrible - Hacker News
As an exercise, try to write a static analyser that simply ignores dynamic imports and just outputs a dependency graph of your static...
Read more >Simon Høiberg on Twitter: "JavaScript Tip Avoid default ...
JavaScript Tip Avoid default exports. You will get a better developer experience, especially if you're using TypeScript. If you're using CommonJS, ...
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 Free
Top 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
We are currently compiling this package in the CommonJS format, the quirkiness we are seeing here is a side-effect of the TypeScript compiler. Now that Node.js 12 is no longer supported we intend to compile to ESM instead.
There are no intentions to have this package contain both ESM and CommonJS entry points and we’d rather opt for a pure ESM package instead. Node.js provides interoperability between these two so that it should ‘just work’ so I expect this will improve the developer experience.
Are you sure? https://antfu.me/posts/publish-esm-and-cjs
I’ve bundled for both without any major issues.