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

Consider publishing as an ESM module only #3983

Closed
dyladan opened this issue Jul 12, 2023 · 4 comments
Closed

Consider publishing as an ESM module only #3983

dyladan opened this issue Jul 12, 2023 · 4 comments

Comments

@dyladan
Copy link
Member

dyladan commented Jul 12, 2023

Maybe we should consider publishing only an ECMAScript module and removing commonjs entirely from our bundle? Node 12 (our minimum node version) and later supports ES modules.

Originally posted by @dyladan in #3976 (comment)

Our dual publishing scheme has always been a little bit fragile and has caused unexpected issues in the past. I believe if we publish an ES Module with the package.json "type" of "module" we should still be able to be required by users using commonjs since node supports mixed esm/commonjs runtime.

@dyladan
Copy link
Member Author

dyladan commented Jul 12, 2023

TODO: test that an ESM module can be required by a CommonJS module/app

@loren138
Copy link

loren138 commented Jul 12, 2023

Here's a writeup from another author who moved all of his packages to ESM only: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
You cannot require an ES module, you can await import() it though

@dyladan
Copy link
Member Author

dyladan commented Jul 12, 2023

Thanks for the link. For now, I think the limitations are too severe for us.

@trentm
Copy link
Contributor

trentm commented Jul 13, 2023

Here is some advice in the Node.js core docs: https://nodejs.org/api/packages.html#dual-commonjses-module-packages
However, every option has limitations.

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

3 participants