Open bradzacher opened 1 week ago
I don't think this has to do with the import being twice, but rather module detection? This one rewrites paths too: https://www.typescriptlang.org/play/?rewriteRelativeImportExtensions=true#code/JYWwDg9gTgLgBAcgHQHoBmEICYkwM4IDcAsAFCiSwAUy6muBAlGUA
Looks like you might be right.
export {};
import('./foo.js')
This also correctly transforms the extension.
@andrewbranch
FWIW I'm not sure that this is incorrect behavior; this transformation was only intended on applying in modules, so if we don't think a file is a module, then it won't happen.
What condition are you running under where the file is not a module?
(Maybe we should rewrite imports in import
nodes in scripts, given they can appear there?)
If you're working in LTS node then the only way to access ESM in CJS is via import
expressions.
But it's not a real usecase I had in mind -- I was just testing the feature and this surprised me because there was no mention of it being restricted on the announcement, and there aren't docs yet (https://www.typescriptlang.org/tsconfig/#rewriteRelativeImportExtensions :sad:).
To be clear a "module" to us means "not a global script"; CJS are modules in this scheme.
🔎 Search Terms
rewriteRelativeImportExtensions, import expression
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play/?rewriteRelativeImportExtensions=true#code/PTAEEsFsAcHsCcAuoDkA6YAzWs2IM4oDcAsAFBRxIAU6WOehAlOUA
💻 Code
Test One
Test Two
🙁 Actual behavior
JS Output
Test One
Test Two
🙂 Expected behavior
JS Output
Test One
Test Two
Additional information about the issue
No response