Node.js ESM support
See original GitHub issueUnfortunately, Node.js didn’t add support for "module"
field that is supported by bundlers such as webpack, and introduced their own resolve logic.
To add Node.js ESM support instead of /esm
submodule we need to add .mjs
version next to CommonJS files. That would be a breaking change so we should introduce it in v3.
Thank you Node.js, very nice.
See the issue: https://github.com/date-fns/date-fns/issues/1779
Issue Analytics
- State:
- Created 3 years ago
- Reactions:16
- Comments:5 (2 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 provides interoperability between them and its original module format, ...
Read more >What does it take to support Node.js ESM? – The Guild
ECMAScript modules, also known as ESM, is the official standard format to package JavaScript, and fortunately Node.js supports it .
Read more >Getting Started with (and Surviving) Node.js ESM
Arguably the biggest feature and pain with Node.js' ESM support is not ESM itself, but rather the new exports field in package.json ,...
Read more >Documentation - ECMAScript Modules in Node.js - TypeScript
For the last few years, Node.js has been working to support running ECMAScript modules (ESM). This has been a very difficult feature to...
Read more >Using ECMAScript modules (ESM) with Node.js
Using official ES module support. Let's start with the first (and official) way provided by Node.js io use ES modules in your Node...
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
@kossnocorp maybe it would be an idea to move to pure ESM for v3, like Sindre Sorhus has been doing with his modules:
https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
@kossnocorp it is possible to support native Node.js ESM without breaking changes. I’ve just done so successfully in
date-fns-tz
. There are a few things to do:./format
to./format/index.js
"type": "commonjs"
to the mainpackage.json
package.json
inside the./esm
folder containing{"type": "module"}
"type": "module"
to thepackage.json
of each function in theesm
folderexports
field to the mainpackage.json
similar to what I’ve done in date-fns-tz#package.json.The last will be a proper mess because there are a gazillion files being exported from
date-fns
, but it should work…