Skip to content

Support ES2023 and ES2024 targets when using SWC #2160

Open

Description

@felipeplets

Search Terms

  • swc
  • ES2024
  • ES2023

Expected Behavior

  • SWC since version 1.8.0 (2024-11-04) supports ES2023 and ES2024
  • Once using ts-node with swc having 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?:

Activity

  1. felipeplets commented on May 1, 2025

    @felipeplets
    Author

    @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.

  2. tianyingchun commented on Jun 1, 2025

    @tianyingchun

    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

  3. wenerme commented on Jul 14, 2025

    @wenerme

    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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions