Hello, Modules!

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 personall…


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:

  1. Pure: Rip off the bandaid and completely move to JavaScript Modules.
  2. 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


Print Share Comment Cite Upload Translate Updates
APA

Sindre Sorhus | Sciencx (2021-05-05T17:41:30+00:00) Hello, Modules!. Retrieved from https://www.scien.cx/2021/05/05/hello-modules/

MLA
" » Hello, Modules!." Sindre Sorhus | Sciencx - Wednesday May 5, 2021, https://www.scien.cx/2021/05/05/hello-modules/
HARVARD
Sindre Sorhus | Sciencx Wednesday May 5, 2021 » Hello, Modules!., viewed ,<https://www.scien.cx/2021/05/05/hello-modules/>
VANCOUVER
Sindre Sorhus | Sciencx - » Hello, Modules!. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/05/hello-modules/
CHICAGO
" » Hello, Modules!." Sindre Sorhus | Sciencx - Accessed . https://www.scien.cx/2021/05/05/hello-modules/
IEEE
" » Hello, Modules!." Sindre Sorhus | Sciencx [Online]. Available: https://www.scien.cx/2021/05/05/hello-modules/. [Accessed: ]
rf:citation
» Hello, Modules! | Sindre Sorhus | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.