Repository navigation
ReReview the Issue : Compiled JavaScript import is missing file extension #47188
Description
Activity
DanielRosenwasser commented
on Dec 20, 2021 MemberMore actionsThe reason that System.js and AMD work is because those systems define a set of conventions for how a module is resolved at runtime, and if you omit the module's extension, they'll still perform a
.jslookup. With ES modules, the same runtime lookup isn't built-in.There is a lot of discussion on that thread, along with several linked threads that can provide some background - specifically
- Compiled JavaScript import is missing file extension #40878
- [FEATURE] absolute->relative module path transformation #15479
- TypeScript and <script type="module"></script> #13422
Unfortunately we can't reiterate the same points over and over. I encourage you to read through these discussions, and I hope you understand that the problem space is not an easy one to tackle for the general case.
Reacted by Martin Johns and Bruce Pascoe- addedDuplicateAn existing issue was already createdAn existing issue was already created
on Dec 20, 2021 To add to the above: TypeScript in general doesn't touch your import specifiers, regardless of the setting of
"module". The bug, if there is one at all, is that there is not (yet) a module resolution mode in tsc that corresponds to the runtime behavior of ESM-based engines; they're all too lenient. In all cases you're meant to use the specifier that works at runtime, that's just not properly enforced in ESM codebases. From what I understand, this is a big part of what thenode12andnodenextmodule modes are meant to solve.jogibear9988 commented
on Dec 21, 2021 AuthorMore actionsBut also Typescript does do a lookup to find the Modules. And it also does that acording to some rules. Why should it not be possible to do this also in the compilation process?
In my build process, I only have a small gulpfile wich changes the imports (see: https://github.com/node-projects/web-component-designer-demo/blob/master/gulpfile.cjs), but okay I do not respect every rule wich is mention in the node spec.
Typescript already needs to finde the imported file, so why can't it write that path to the file?
It does not need to be the standard, but why no option to allow this?
Is it really needed people add a bundling step, only to change the import paths?typescript-bot commented
on Dec 23, 2021 ContributorMore actionsThis issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.
jogibear9988 commented
on Jan 14, 2022 AuthorMore actionsI've created a pull request wich wich solve this for raltive imports, see:
I've added a compiler switch:
appendModuleExtension- locked as resolved and limited conversation to collaborators
on Oct 22, 2025
This issue was closed as "works as intended" see: #40878
How can that be?
Why are imports transpiled to workin ones when using "System" or "Amd" as module type. But don't work if I use "ESM" modules.