Skip to content

Instantly share code, notes, and snippets.

@behrangsa
Created December 20, 2022 12:23
Show Gist options
  • Save behrangsa/2faca96f8f68a51276634d3ddf9ef5ea to your computer and use it in GitHub Desktop.
Save behrangsa/2faca96f8f68a51276634d3ddf9ef5ea to your computer and use it in GitHub Desktop.
What is an ESM module?

What is an ESM module?

ESMs (ECMAScript modules) are the official standard format to package JavaScript code for reuse. Modules are defined using import and export statements. 1

Default exports in ESM

The way we export "things" from our libraries impacts the way they can get imported by clients of our libraries.

For example, if we define a module and export cheese from it as the default export:

export default cheese;
// same as `export { cheese as default };`

Then clients of our library should import it like this:

import cheese from 'my-library';

But had we defined cheese as a non-default export:

export cheese;

Then we should have used a different syntax to import it:

import { cheese } from 'my-library';
  • #javascript
  • #typescript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment