`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)
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
@aramissennyeydd You can set module.ignoreDynamic: true
to keep dynamic imports.
I'll close this issue with a documentation commit
Oh it was documented. https://swc.rs/docs/configuration/modules#ignoredynamic
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.