You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rewriteRelativeImportExtensions does not rewrite the extension for an import expressions unless the file is detected to be a moduleΒ #60599
changed the title [-]rewriteRelativeImportExtensions does not rewrite the extension for an import expressions unless there is an import declaration for the same module[/-][+]rewriteRelativeImportExtensions does not rewrite the extension for an import expressions unless the file is detected to be a module[/+]on Nov 26, 2024
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:).
Activity
jakebailey commentedon Nov 26, 2024
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
bradzacher commentedon Nov 26, 2024
Looks like you might be right.
playground
This also correctly transforms the extension.
[-]rewriteRelativeImportExtensions does not rewrite the extension for an import expressions unless there is an import declaration for the same module[/-][+]rewriteRelativeImportExtensions does not rewrite the extension for an import expressions unless the file is detected to be a module[/+]jakebailey commentedon Nov 26, 2024
Andrew Branch (@andrewbranch)
jakebailey commentedon Nov 26, 2024
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
importnodes in scripts, given they can appear there?)bradzacher commentedon Nov 26, 2024
If you're working in LTS node then the only way to access ESM in CJS is via
importexpressions.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:).
jakebailey commentedon Nov 26, 2024
To be clear a "module" to us means "not a global script"; CJS are modules in this scheme.