This content originally appeared on ? Sindre Sorhus’ blog - Medium and was authored by Sindre Sorhus
JavaScript Modules, also known as ESM, is finally here!
It has already been available for some time in modern browsers, but we can now finally use it in Node.js, thanks to Node.js 10 becoming obsolete.
As I wrote about earlier this year, I have personally been waiting for this day for 10 years.
Here’s a good overview of JavaScript Modules.
What are the benefits of JavaScript Modules over CommonJS?
- Unified syntax. Helps with teaching.
- Browser compatibility.
- Top-level await. Nice for scripts and command-line tools.
- Import both default export and named exports in the same statement.
- Re-export syntax.
- Potentially faster import step.
- Official loader hooks (still draft).
I’m a package maintainer, what should I do?
There are two ways to handle the migration:
- Pure: Rip off the bandaid and completely move to JavaScript Modules.
- Dual: Introduce a build step that transpiles a CommonJS fallback.
I would recommend 1, which is what I’m going with.
Please first read everything here.
You can then follow my migration guide.
Hello, Modules! was originally published in ? Sindre Sorhus’ blog on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on ? Sindre Sorhus’ blog - Medium and was authored by Sindre Sorhus
Sindre Sorhus | Sciencx (2021-05-05T17:41:30+00:00) Hello, Modules!. Retrieved from https://www.scien.cx/2021/05/05/hello-modules/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.