Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exports map with ESM variant #67

Closed
lukeed opened this issue Nov 10, 2020 · 1 comment
Closed

Add exports map with ESM variant #67

lukeed opened this issue Nov 10, 2020 · 1 comment

Comments

@lukeed
Copy link

lukeed commented Nov 10, 2020

It'd be nice to offer a supplemental ESM build that's linked via:

  • "module" in package.json
  • the import key inside each exports entry (inside package.json too)

This'd end up looking something like:

{
  // ...
  "module": "dist/index.mjs",
  "main": "dist/index.js",
  // ...
  "exports": {
    ".": {
      "require": "./dist/index.js",
      "import": "./dist/index.mjs"
    },
    "./from": {
      "require": "./from/index.js",
      "import": "./from/index.mjs"
    }
  }
  // ...
}

This allows for native ESM resolution in Node.js (12.x and >=14) in supporting environments w/o sacrificing CommonJS (default) support. Also allows bundler(s) to pick up the ESM entry, too.

There's one gotcha – Node 13.0 thru 13.7 don't support this version of exports.
This can be patched – but only if you decide to keep the default exports (module.exports / export default) that you currently have. This means that the the addition remains non-breaking, even w/ these Node versions.


I can PR these changes if desired.

@jimmywarting jimmywarting mentioned this issue Apr 20, 2021
@jimmywarting
Copy link
Contributor

The v3 have switched to ESM - no longer provide a commonjs variant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants