-
Notifications
You must be signed in to change notification settings - Fork 12.8k
cannot consume compiled js files targeted to browser #33882
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
Comments
This isn't ideal but I'll note for the record that you can add the |
TypeScript does not modify the module specifier. This is very intentional, because any modification would work for some, but not work for anyone, so TypeScript is avoiding getting into that fight. |
I generally agree with that sentiment, too - however unlike with If there were an option to have it so automatically-added imports included the |
Probably we should have auto-import detect if the prevailing style of import in the file uses extensions or not, but rewriting the import path is not the correct solution. |
Right, and I agree - I just think there should be an option to have auto-import add the |
Sorry to comment on a closed issue, but I have just encountered this problem myself. The suggested solution to add the Would it not be possible to add a {
"compilerOptions": {
"module": "ES2020",
"moduleExtension": "js" // or "mjs", or anything else a developer needs
}
} That seems like a sensible solution to this, and it would give developers the freedom they need on a per-project basis. |
I'm also running into this issue; I think it's plainly almost unimaginable that a simple .ts file using modules and targeting modern browsers and ES modules cannot be compiled to a working javascript file in the browser. I'm using the workaround suggested above (using an explicit .js module reference in the typescript file, like "import {Foo} from './module.js' ", but this feels rather strange, although it works well in the browser. |
This has been reported here #27287 but closed without being fixed.
Comment summarizing the issue:
Expected behavior:
Transpiled code should be
import {Foo} from "./module.js"
This prevents using TS packages in browsers (in modern development environment, without bundling and wepacking). Browsers expect import to point to the exact filename.
The text was updated successfully, but these errors were encountered: