-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Open
Labels
Description
Describe the bug
swc is leaving a trailing _ts_rewrite_relative_import_extension wrapper on await import statements when using rewriteRelativeImportExtensions: true option in jsc.
This is not expected for me and predictably causes ReferenceError: _ts_rewrite_relative_import_extension is not defined when running output code.
Please excuse me if I've mis-configured or missed something.
Input code
import path from 'path';
import fs from 'fs-extra';
export async function loadNode(file: string) {
const pathToFile = path.resolve('base', `${file}.ts`);
if (await fs.pathExists(pathToFile)) {
const { default: _default, ...rest } = await import(pathToFile);
return rest;
}
return {};
}Config
{
"$schema": "https://swc.rs/schema.json",
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false,
"decorators": true,
"dynamicImport": true
},
"rewriteRelativeImportExtensions": true,
"target": "es2024",
},
"module": {
"type": "es6"
},
"sourceMaps": true,
"isModule": true
}Link to the code that reproduces this issue
SWC Info output
No response
Expected behavior
The await import statement should be left as is, or if transforming is done, there should not be a leftover _ts_rewrite_relative_import_extension in the output.
Actual behavior
_ts_rewrite_relative_import_extension is left in the output, but this is never defined.
Version
1.13.20
Additional context
Originally encountered on 1.15.3, but swc-playground indicates it is still occurring in latest.