Support ES2023 and ES2024 targets when using SWC
Search Terms
- swc
- ES2024
- ES2023
Expected Behavior
- SWC since version 1.8.0 (2024-11-04) supports ES2023 and ES2024
- Once using
ts-nodewithswchaving a target equals to ES2023 or ES2024 the application should execute correctly
Actual Behavior
- The application fails with error:
return bindings.transformSync(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions));
^
Error: x jsc.target should be es5 or upper to use getter / setter
Steps to reproduce the problem
In a project using ts-node with swc set the target to ES2023 or ES2024 and it will fail. Once you set the target as ES2022 the project work as expected.
Minimal reproduction
Same as above
Specifications
- ts-node version: 10.9.2
- node version: 22.15.0
- TypeScript version: 5.8.3
- tsconfig.json, if you're using one:
{}
- package.json:
{}
- Operating system and version:
- If Windows, are you using WSL or WSL2?:
@cspotcode I've opened a PR resolving this issue, but I would also like to propose that instead of automatically downgrading the target to ES3 in this line we should raise an exception letting the user know that the specified target is not currently supported.
it seems that ts-node have no activity over 1year. maybe we need to switch it to swc
see here. https://github.com/hyperse-io/ts-node
Workaround for now
put this to patches/ts-node.patch
diff --git a/dist/transpilers/swc.js b/dist/transpilers/swc.js
index c334bd3b18b292c3f865639dca4080ff3dfe53e8..8fc480051355d30d15bf025b482e8330e9f839c0 100644
--- a/dist/transpilers/swc.js
+++ b/dist/transpilers/swc.js
@@ -60,6 +60,8 @@ exports.targetMapping.set(/* ts.ScriptTarget.ES2019 */ 6, 'es2019');
exports.targetMapping.set(/* ts.ScriptTarget.ES2020 */ 7, 'es2020');
exports.targetMapping.set(/* ts.ScriptTarget.ES2021 */ 8, 'es2021');
exports.targetMapping.set(/* ts.ScriptTarget.ES2022 */ 9, 'es2022');
+exports.targetMapping.set(/* ts.ScriptTarget.ES2023 */ 10, 'es2023');
+exports.targetMapping.set(/* ts.ScriptTarget.ES2024 */ 11, 'es2024');
exports.targetMapping.set(/* ts.ScriptTarget.ESNext */ 99, 'esnext');
/**
* @internal
@@ -167,7 +169,7 @@ function createSwcOptions(compilerOptions, nodeModuleEmitKind, swcInstance, swcD
: {}),
}
: undefined,
- swcrc: false,
+ swcrc: true,
jsc: {
externalHelpers: importHelpers,
parser: {
add this to pnpm-workspace.yaml
patchedDependencies:
ts-node: patches/ts-node.patch
then
pnpm i