Skip to content

Instantly share code, notes, and snippets.

View 9a-aaaaaaaa's full-sized avatar
🌴
fucking works

9a 9a-aaaaaaaa

🌴
fucking works
  • BeiJing
View GitHub Profile
@9a-aaaaaaaa
9a-aaaaaaaa / esm-package.md
Created October 10, 2022 14:41 — forked from sindresorhus/esm-package.md
Pure ESM package

Pure ESM package

The package linked to from here is now pure ESM. It cannot be require()'d from CommonJS.

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. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.