Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jogibear9988 opened this issue Dec 18, 2021 · 5 comments
Closed
Labels
Duplicate An existing issue was already created

Comments

@jogibear9988
Copy link

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.

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Dec 20, 2021

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.

@DanielRosenwasser DanielRosenwasser added the Duplicate An existing issue was already created label Dec 20, 2021
@fatcerberus
Copy link

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.

@jogibear9988
Copy link
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?

@typescript-bot
Copy link
Collaborator

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

@jogibear9988
Copy link
Author

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

#47436

I've added a compiler switch:

   appendModuleExtension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants