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

Support typescript@4.5 .js import extension requirement #317

Closed
vjpr opened this issue Nov 2, 2021 · 4 comments
Closed

Support typescript@4.5 .js import extension requirement #317

vjpr opened this issue Nov 2, 2021 · 4 comments

Comments

@vjpr
Copy link

vjpr commented Nov 2, 2021

ESM requires all relative imports to use an extension. TS requires insists on using .js inside .ts files which is left untouched in the output file.

See: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-5.html

relative import paths need to use extensions

When a .ts file is compiled as an ES module, ECMAScript import/export syntax is left alone in the .js output

As a result, it will have to be rewritten to use the extension of the output of foo.ts - so bar.ts will instead have to import from ./foo.js.


When trying to resolve #src/index.js from a TypeScript file, it should search for #src/index.ts. The extension needs to be stripped during search.

I use this for transpilation on-the-fly.

Would be nice to have a setting to accomplish this.

Workaround

I could just remove '.js' extensions before passing them to enhanced-resolve.

@alexander-akait
Copy link
Member

We have options and plugins, you can do it using them, it should be done in ts-loader

@vjpr
Copy link
Author

vjpr commented Nov 2, 2021

I am actually using it in an node --experimental-loader hook. Currently I am planning to just chop off .js extensions, but then there is a perf impact if I chop off the extension and then it must search all extension.

We have options

Is there an option I am missing that handles this?

@alexander-akait
Copy link
Member

alexander-akait commented Nov 2, 2021

You search this TypeStrong/ts-loader#1383

@vjpr
Copy link
Author

vjpr commented Nov 2, 2021

Thanks, this logic is TS-specific so should not be inside enhanced-resolve as you mention.

@vjpr vjpr closed this as completed Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants