Skip to content

ReReview the Issue : Compiled JavaScript import is missing file extension #47188

Description

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.

Activity

  1. DanielRosenwasser commented on Dec 20, 2021

    @DanielRosenwasser
    Member

    The 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 .js lookup. 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

    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.

  2. fatcerberus commented on Dec 21, 2021

    @fatcerberus

    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 the node12 and nodenext module modes are meant to solve.

  3. jogibear9988 commented on Dec 21, 2021

    @jogibear9988
    Author

    But 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?

  4. typescript-bot commented on Dec 23, 2021

    @typescript-bot
    Contributor

    This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  5. jogibear9988 commented on Jan 14, 2022

    @jogibear9988
    Author

    I've created a pull request wich wich solve this for raltive imports, see:

    #47436

    I've added a compiler switch:

       appendModuleExtension
    
  6. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions