Add ESM support
See original GitHub issueWhen import
ing a CommonJS library, it’s flattened into a single object, and you’re unable to take advantage of any ESM features. However if you add a few lines to your package.json
and a esm.mjs
wrapper file that simply re-exports the contents of index.js
, then ESM users will be able to take full advantage of ESM features without any changes needed to your source code, and without affecting any CommonJS users. The package.json
changes would be as simple as:
"main": "index.js",
"exports": {
".": [
{"require": "index.js", "import": "esm.mjs"},
"index.js"
],
"./": "./"
}
The "index.js"
fallback is only necessary to avoid package.json
parsing errors in some older versions of Node, which would affect CommonJS users as well. If this library ever supports only Node 14+ in the future, the fallback could be removed.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:13
- Comments:7 (1 by maintainers)
Top Results From Across the Web
What does it take to support Node.js ESM? – The Guild
To add support ESM for Node.js, you have two alternatives: build your library into ESM Compatible modules with the extension .mjs , and...
Read more >Getting Started with (and Surviving) Node.js ESM
The Node.js ecosystem is shifting towards ESM. We examine what lies in store for application and library authors, learn some of challenges ...
Read more >How to use ESM on the web and in Node.js - ByteofDev
The simplest way to use ESM on the web is by utilizing the native support for it. For about over 95% of users...
Read more >Using ECMAScript modules (ESM) with Node.js
Learn about using ES modules in Node.js today and get a closer look at how you can migrate your codebase to make use...
Read more >ECMAScript modules | Node.js v19.3.0 Documentation
Node.js fully supports ECMAScript modules as they are currently specified and ... The Import Assertions proposal adds an inline syntax for module import ......
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
yea submit a pr I’d love to take a look at it
I would be happy to open a pull request but wish to confirm interest from the maintainers first.