Skip to content

Instantly share code, notes, and snippets.

@skyrpex
Forked from sindresorhus/esm-package.md
Created April 20, 2022 11:56
Show Gist options
  • Select an option

  • Save skyrpex/44a050ffed671580b26f372793ede674 to your computer and use it in GitHub Desktop.

Select an option

Save skyrpex/44a050ffed671580b26f372793ede674 to your computer and use it in GitHub Desktop.
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package.
  2. If the package is used in an async context, you could use await import(…) instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.

I would strongly recommend moving to ESM. ESM can still import CommonJS packages, but CommonJS cannot import ESM packages synchronously.

ESM is natively supported by Node.js 12 and later.

You can read more about my ESM plans.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment