-
Notifications
You must be signed in to change notification settings - Fork 138
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
Dynamic import not act as expected as typescript transpiled #778
Comments
alangpierce
added a commit
that referenced
this issue
Mar 26, 2023
Fixes #778 Previously, `import()` transpiled to a promise-wrapped `require`, which worked fine for ESM-to-CJS-transpiled modules, but when importing plain CJS modules, the behavior was inconsistent with other implementations. In that case, we needed to call `_interopRequireWildcard` to nest the module under a `default` key. I tested to confirm that this updated behavior is consistent with Node ESM-to-CJS dynamic import, as well as Babel, TypeScript, and swc, so this change will be considered a bug fix rather than a breaking change, even though it is possible that existing use cases may have been relying on the old behavior.
alangpierce
added a commit
that referenced
this issue
Mar 26, 2023
Fixes #778 Previously, `import()` transpiled to a promise-wrapped `require`, which worked fine for ESM-to-CJS-transpiled modules, but when importing plain CJS modules, the behavior was inconsistent with other implementations. In that case, we needed to call `_interopRequireWildcard` to nest the module under a `default` key. I tested to confirm that this updated behavior is consistent with Node ESM-to-CJS dynamic import, as well as Babel, TypeScript, and swc, so this change will be considered a bug fix rather than a breaking change, even though it is possible that existing use cases may have been relying on the old behavior.
Thanks for reporting! I just released a fix in 3.31.0. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the example:
https://sucrase.io/#compareWithBabel=false&compareWithTypeScript=true&code=import%20b%20from%20'a'%3B%0A%0Aasync%20function%20a%20()%20%7B%0A%20%20console.log(b)%3B%0A%20%20const%20c%20%3D%20await%20import('a')%3B%0A%20%20console.log(c)%3B%0A%20%20console.log(c.default)%3B%0A%7D
While static import is transpiled to use
_interopRequireDefault
, but dynamic import is not transpiled to use__importStar
, so in runtimec.default
is not defined.The text was updated successfully, but these errors were encountered: