-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
💻
- Would you like to work on this feature?
What problem are you trying to solve?
I use rewriteImportExtensions
to have babel automatically convert my static imports from .mts
to .mjs
.
However, I had to realize that @babel/preset-typescript
also applies this to dynamic imports:
const something = await import(path.join(someVariable, "./myFile.mts"))
Which effectively results in:
const something = await import(path.join(someVariable, "./myFile.mjs"))
Which isn't what I expected babel to do since it's a dynamic import.
However, I fully understand that there's a valid use case to automatically have babel rewrite dynamic imports.
Since newer versions of node support running TypeScript files directly (i.e. where it is allowed to have an .mts
file extension), I would like to propose an additional flag that controls whether dynamic imports should be rewritten (or left alone) as well.
Describe the solution you'd like
A flag like rewriteDynamicImportExtensions
that controls whether dynamic imports should be rewritten or not.
The default value could be set to whatever rewriteImportExtensions
is set to, so current users will have the same behaviour as before. This means it's a non-breaking change for existing users, but allows users like me to opt out of the feature.
Describe alternatives you've considered
The alternative is to set rewriteImportExtensions
to false
and do my own rewriting that ignores dynamic imports.
Documentation, Adoption, Migration Strategy
No response