analyze-npm icon indicating copy to clipboard operation
analyze-npm copied to clipboard

ESM packages that don't specify "module"

Open web-padawan opened this issue 6 years ago • 1 comments

Now when Node has support for modules, some packages started to care about ESM version.

It turns out the "module" field isn't always the best solution, because of webpack. See for example this PR where it was decided to remove it: https://github.com/markedjs/marked/pull/1571#issuecomment-562891963

Also I found this article relevant: https://2ality.com/2019/10/hybrid-npm-packages.html

@FredKSchott would you consider adding more ways to discover ESM packages?

This is important for me as a library maintainer: I was hoping to get @pika/web and CDN support when upgrading to ESM version of dependency, but so far I'm out of luck.

web-padawan avatar Dec 13 '19 08:12 web-padawan

Module field is OK - the only thing you have to do to make it work is to expose the same shape from each format. If that requires a major bump on your side because of CJS consumers then just do it. Yes - it will be a little bit worse for CJS consumers because they will have to either use .default or destructure named export which is less than ideal bit its really not that bad in the end. The difference is just visual so it’s better to get over it and start shipping stuff instead of hanging to a possibility to export a single thing from CJS in a flat~ manner (whereas in ESM you always export a bag of things).

Andarist avatar Dec 14 '19 16:12 Andarist