TypeScript cannot emit valid ES modules due to file extension issue (2020)
github.com
github.com
Open source developers at big companies are often incredibly competent as well as under supported compared with those that work on products that bring in revenue. We don’t also have to emotionally attack them.
https://github.com/virtualstate/promise/blob/main/scripts/co...
https://github.com/virtualstate/focus/blob/main/scripts/corr...
https://github.com/virtualstate/navigation/blob/main/scripts...
This same script was replicated to near every repository I have worked on, including making its way into a few different production services where Node.js + ESM was used for deployment
Eventually I had turned into a utility module that could be used wider, which starts to lean into import map generation
https://github.com/virtualstate/impack#usage
You can see it being used here as a function, but can be used as a cli tool too:
https://github.com/virtualstate/listen/blob/033bf8effcbde5c8...
"moduleResolution": "node16"
In your TS files, even if the import is a file with the extension .ts (tsc will handle): import { test } from './importMe.js';
[0]: https://www.typescriptlang.org/tsconfig#moduleResolutionIt’s honestly extraordinarily unintuitive and frustrating, and the team’s arguments are more philosophical than practical (along the lines of “typescript will never deviate from JavaScript language specification”). I’m not very sympathetic since the entire language is incompatible with a JS interpreter, and importing from a file that doesn’t actually exist is really poor DevX.
I really wish the TS team had not forced people to decide between ESM (the future of JS modules) or importing files that don’t actually exist everywhere in the codebase.
> entire language is incompatible with a JS interpreter
If this proposal will ever be accepted, TS will be (in large parts) valid JS: https://github.com/tc39/proposal-type-annotations
[0] https://devblogs.microsoft.com/typescript/announcing-typescr...
It touches on exactly this topic in the timestamp in the link.