swc-project / swc

Rust-based platform for the Web

Home Page:https://swc.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`dynamicImport` option doesn't work with CJS export TypeScript

aramissennyeydd opened this issue · comments

Describe the bug

I'm working to allow Backstage to use ESM modules using dynamic imports as part of our migration path away from CJS, backstage/backstage#22638. We're using Rollup for production builds and SWC locally. I'm unable to get SWC to keep dynamic imports in our output.

Input code

console.log(import('./test.mjs'));

Config

{
    filename,
    sourceMaps: 'inline',
    module: { type: 'commonjs' },
    jsc: {
        target: 'es2022',
        parser: {
          syntax: 'typescript',
          dynamicImport: true,
        },
      },
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.13&code=H4sIAAAAAAAAA9NILK7MS1bQ0LS1q%2BZSUEjOzysuUShJBRK2ConliZklCpm5BflFJRrqmXnZ6prWKGqMMBTp6YPE9XKzikFqazUBQDmEwl8AAAA%3D&config=H4sIAAAAAAAAA2WPPQ7DMAiF954iYu5QZewNOvQQlkMiR8G2gEi1oty9dn7cVt3gffAeLJemgVEs3Jsll7mJhgW59lmR5NW8sgKaIoplFxWuJ1UpqDeTYNW65A05%2B6AYWDNVnnFj6z4CanjAQgClvbXtYQdTCIK%2FdkDOuz59H2QDRUaRv1wyfpjq%2Fp54OVKBQjdv8Hi0PFMuyG4U%2FCjwmTwTqzs4eZ7r2zPrG1secAA5AQAA

edit: updated to one with dynamicImport set - the behavior is the same.

SWC Info output

No response

Expected behavior

The import statement is preserved

Actual behavior

console.log(Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("./test.mjs"))));

Version

@swc/core: 1.4.8

Additional context

No response

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.