Badge on NPM packages to show support for ESM entry point #634
-
|
Now that ECMAScript modules are widely supported in the NodeJS and JavaScript ecosystem I find myself more often looking explicitly for modern packages that support these modules out of the box. Currently if I look around the NPM site I have trouble to find the right package, as I would first have to dive into the source code of the package to understand if it actually supports ESM. I'd love to see a badge, just like the one that indicates that a package has type definitions available to indicate support (see mockup below). This way I can instantly see if the package supports ESM. Detecting this would work in a similar manner as the TypeScript badge, by analyzing the contents of the |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 68 replies
-
|
Why do you find yourself doing that? node ESM, and transpiled ESM, can import CJS modules just fine; there’s nothing “not modern” about those. in other words, every CJS package supports ESM. |
Beta Was this translation helpful? Give feedback.
-
|
I like how Skypack handles this – e.g. (details on the right): https://www.skypack.dev/view/preact |
Beta Was this translation helpful? Give feedback.
-
|
@jonkoops really interesting request, could definitely see it being useful in a lot of contexts. Wonder if you'd share some additional information about your usage on "supports ES Modules" as "modern". Using JS with CJS modules in a node environment, wouldn't a project be able to get the "modern" label just as easily as if it were shipped as ES Modules based on that actual JS that it contained? I definitely have personal feeling in support of ES Modules as a whole, and am interested in your thoughts on whether a JS library could be "modern" without them. What's more, I ask, because I see "has ES Modules" as only half the story of a bigger request in my work, and that's "is browser ready". This takes into account things like CJS modules or With that in mind, I'd much rather see NPM take the next step in its evolution from Node (only) Package Manger to de facto JS, or even everything, Package Manager and more clearly define the contexts where in a listed package can be used. "Is browser ready" might not even be the only context for that, especially as more and more tools make it into NPM. It might make sense to start clarifying more and more of these contexts (wasm, node, CSS, there was talk of C++ above) so that NPM could support getting users to success even faster than ever. I look forward to more on your thoughts here, and strongly agree that NPM is in a great place to leverage its outsized and growing influence in this area to support a demystification of the ecosystem on any number of axes... +1! |
Beta Was this translation helpful? Give feedback.
-
This makes sense to me. |
Beta Was this translation helpful? Give feedback.
-
|
There's a historic discussion about identifying a number of format details of a package, does it make sense to folks this conversation into there? https://github.com/npm/feedback/discussions/13 |
Beta Was this translation helpful? Give feedback.
-
Yeah for sure, but I could only create them automatically when the package.json has a "exports" section (wich most of them do not have atm.) where these all are listed. If not, it may be possible for a bundler or other local app wich parses the files and searches for the imports, but not for my lib wich only loads the npm's (the other also would be to slow to do live) |
Beta Was this translation helpful? Give feedback.

There's a historic discussion about identifying a number of format details of a package, does it make sense to folks this conversation into there?
https://github.com/npm/feedback/discussions/13