Skip to content

Export ESM module#1518

Open
flying-sheep wants to merge 7 commits intomicrosoft:mainfrom
flying-sheep:pa/esm
Open

Export ESM module#1518
flying-sheep wants to merge 7 commits intomicrosoft:mainfrom
flying-sheep:pa/esm

Conversation

@flying-sheep
Copy link
Copy Markdown
Contributor

@flying-sheep flying-sheep commented May 10, 2026

Allow bundlers to pick the best version, do tree-shaking, …

I checked that the below works with typescript, but I didn’t check if npmjs.com is smart enough to add the little “TS” icon. I assume so according to their docs, but if not, we can re-add the old "types" field.

Details about exports

According to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing:

if you write an import from an ES module, it will look up the import field, and from a CommonJS module, it will look at the require field. If it finds them, it will look for a corresponding declaration file. If you need to point to a different location for your type declarations, you can add a "types" import condition.
[…]
It’s important to note that the CommonJS entrypoint and the ES module entrypoint each needs its own declaration file, even if the contents are the same between them.

and according to npmjs.com’s RFC 46:

If there is not the explicit fields: Resolving the main with both TypeScript and Flow's extra file resolvers (e.g. when distribution/danger.js look for the files ./distribution/danger.js.flow and ./distribution/danger.d.ts)

So in summary, TypeScript 4.7+ should find the .d.ts files, and npmjs.com should therefore resolve it to, but others had problems with that: browserslist/browserslist-useragent-regexp#1545

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

Successfully merging this pull request may close these issues.

1 participant