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

Some modules labeled 'esm' are dual #9

Closed
joyeecheung opened this issue Mar 9, 2024 · 3 comments
Closed

Some modules labeled 'esm' are dual #9

joyeecheung opened this issue Mar 9, 2024 · 3 comments

Comments

@joyeecheung
Copy link

joyeecheung commented Mar 9, 2024

First of all, thanks for doing this project, it's very helpful for looking into the ESM situation in the ecosystem!

I am using the data in data/2024-02-20.json to find high impact packages that are ESM-only in order to test my require(esm) implementation & check the performance. Along the way I noticed that some packages labeled esm seem to be actually dual (at least, the can be both required and imported). So far the packages like this that I've found are:

  • tslib
  • fs-extra
  • axios
  • parse5
  • node-releases (this is just a bunch of .json files so can be required or imported with import attributes)
  • ts-node
  • @eslint-community/regexpp
  • babel-plugin-polyfill-regenerator (and other babel plugins too? This is a transpiled file with __esModule)
  • html-escaper
  • @ungap/structured-clone
  • @emotion/hash
  • @emotion/cache
  • @emotion/sheet
  • @emotion/weak-memoize
  • @swc/helpers
  • @floating-ui/dom
  • css-declaration-sorter
  • @floating-ui/core
  • marked
  • redux
    (still continuing my testing by going through the list..)
@wooorm
Copy link
Owner

wooorm commented Mar 12, 2024

Heya Joyee! Thanks!

I guess it’s the import for ESM and then a default condition for CJS. Feels a bit weird to do it that way instead of the inverse, or instead of the require vs import mutually exclusive conditions.

Did you find more?
I’ll investigate next time I crawl. Or, PR welcome!

@joyeecheung
Copy link
Author

joyeecheung commented Mar 15, 2024

I guess it’s the import for ESM and then a default condition for CJS.

Yes, this seems quite common actually. Also many of them have "type": "module" at the top level package.json, but also another package.json in a folder that has "type": "commonjs", and then in the top level package.json they have conditional exports require or default pointing to that folder (axios, parse5, html-escaper, etc.). Some of them have "type": "module" but then the files resolved via main or exports have .cjs extension (e.g. marked) so could also be loaded just fine as CJS.

I've put the ones I've found (and the script used to load them with require()) in https://github.com/joyeecheung/test-require-esm/blob/main/dual.cjs

@wooorm
Copy link
Owner

wooorm commented May 27, 2024

thanks, done!

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