Get Ready For ESM

JavaScript Modules will soon be a reality for Node.js package maintainers.

This blog post is targeted Node.js package maintainers.

At the end of April 2021, Node.js 10 will be end-of-life, which means that package maintainers can target Node.js 12. This Node.js version has full support for JavaScript Modules, also known as ESM.

From the left: Addy Osmani, Dave Herman, and Sindre Sorhus.

Background

Personally, I have been waiting for ESM to happen for almost 10 years. In 2012, I was sitting at a conference dinner with Addy Osmani, and Dave Herman was asking for feedback on early ESM syntax.

CommonJS has served us well for many years, but ESM comes with many benefits, like language-level syntax, browser support, defaults to strict mode, async loading, top-level await, improved static analysis & tree-shaking, and more.

If you’re not familiar with ESM, start by reading the MDN overview. The Node.js docs on ESM are also very comprehensive, and IMHO required reading.

Introducing a new module system is not a simple thing. The ecosystem is huge and it’s going to take many years to move the whole ecosystem. Luckily, smart people have spent a lot of effort into making these module systems fairly compatible. ESM can import CommonJS and CommonJS can import ESM. However, and it’s a big *however*, CommonJS can only import ESM asynchronously.

Migrating

There are two ways to move your packages to ESM:

  1. Pure ESM
    This has the benefit that it’s easier to set up. You just add “type”: “module” to your package.json, require Node.js 12, update docs & code examples, and do a major release.
  2. Dual — ESM with a build step that transpiles a CommonJS fallback
    This requires you to also set up a build step and add a exports field to your package.json. Read more

Personally, I plan to do 1 as I think it’s better to rip off the bandaid and push the ecosystem forward.

The Plan

I intend to move most of my 1K+ packages to pure ESM within 2021. I’m hoping other package maintainers will follow.

If you’re a Node.js package maintainer, please consider setting aside some time in May to move your packages to ESM. It will benefit the whole ecosystem!

You can read more about my ESM plan here.

If you have any questions about moving to ESM, you can ask here.

FAQ

What’s the benefit of ESM over CommonJS for server-only packages?


Get Ready For ESM 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

JavaScript Modules will soon be a reality for Node.js package maintainers.

This blog post is targeted Node.js package maintainers.

At the end of April 2021, Node.js 10 will be end-of-life, which means that package maintainers can target Node.js 12. This Node.js version has full support for JavaScript Modules, also known as ESM.

From the left: Addy Osmani, Dave Herman, and Sindre Sorhus.

Background

Personally, I have been waiting for ESM to happen for almost 10 years. In 2012, I was sitting at a conference dinner with Addy Osmani, and Dave Herman was asking for feedback on early ESM syntax.

CommonJS has served us well for many years, but ESM comes with many benefits, like language-level syntax, browser support, defaults to strict mode, async loading, top-level await, improved static analysis & tree-shaking, and more.

If you’re not familiar with ESM, start by reading the MDN overview. The Node.js docs on ESM are also very comprehensive, and IMHO required reading.

Introducing a new module system is not a simple thing. The ecosystem is huge and it’s going to take many years to move the whole ecosystem. Luckily, smart people have spent a lot of effort into making these module systems fairly compatible. ESM can import CommonJS and CommonJS can import ESM. However, and it’s a big *however*, CommonJS can only import ESM asynchronously.

Migrating

There are two ways to move your packages to ESM:

  1. Pure ESM
    This has the benefit that it’s easier to set up. You just add "type": "module" to your package.json, require Node.js 12, update docs & code examples, and do a major release.
  2. Dual — ESM with a build step that transpiles a CommonJS fallback
    This requires you to also set up a build step and add a exports field to your package.json. Read more

Personally, I plan to do 1 as I think it’s better to rip off the bandaid and push the ecosystem forward.

The Plan

I intend to move most of my 1K+ packages to pure ESM within 2021. I’m hoping other package maintainers will follow.

If you’re a Node.js package maintainer, please consider setting aside some time in May to move your packages to ESM. It will benefit the whole ecosystem!

You can read more about my ESM plan here.

If you have any questions about moving to ESM, you can ask here.

FAQ

What’s the benefit of ESM over CommonJS for server-only packages?


Get Ready For ESM 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-01-13T09:56:25+00:00) Get Ready For ESM. Retrieved from https://www.scien.cx/2021/01/13/get-ready-for-esm/

MLA
" » Get Ready For ESM." Sindre Sorhus | Sciencx - Wednesday January 13, 2021, https://www.scien.cx/2021/01/13/get-ready-for-esm/
HARVARD
Sindre Sorhus | Sciencx Wednesday January 13, 2021 » Get Ready For ESM., viewed ,<https://www.scien.cx/2021/01/13/get-ready-for-esm/>
VANCOUVER
Sindre Sorhus | Sciencx - » Get Ready For ESM. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/01/13/get-ready-for-esm/
CHICAGO
" » Get Ready For ESM." Sindre Sorhus | Sciencx - Accessed . https://www.scien.cx/2021/01/13/get-ready-for-esm/
IEEE
" » Get Ready For ESM." Sindre Sorhus | Sciencx [Online]. Available: https://www.scien.cx/2021/01/13/get-ready-for-esm/. [Accessed: ]
rf:citation
» Get Ready For ESM | Sindre Sorhus | Sciencx | https://www.scien.cx/2021/01/13/get-ready-for-esm/ |

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.