Use explicit extensions systematically
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
I've noticed that `format: ["cjs", "esm", "iife"],` and `format: ["cjs", "esm"]` leads to different extensions being used. In the first scenario, `.js` is the ES Module. In the second scenario, `.js` is the CommonJS file.
This behaviour can be confusing, all the more that if you add `type: "module"` to a package.json, it changes the way `.js` files are interpreted. If you enable it, they are considered ES Modules (so a CommonJS export with extension `.js` will fail at import), if you disable it that's the contrary.
I lost a few hours trying to grasp all those concept, and would have avoided the issue altogether with more explicit extensions.
It would probably be better to be always explicit, with `.cjs` for the CommonJS export and `.mjs` export. Or if it's a breaking change, make this an option.
I don't know if this behaviour comes from Tsup or Esbuild, so I can open an issue at Esbuild if necessary.
Contributor guide
Assessment
This issue has not been assessed yet.