Skip to content

Setting emitAssertForImportAttributes no longer works in Node.js 22 with latest swc #2117

Open

Description

@KidkArolis

Expected Behavior

Running this with ts-node should work when swc: true is set:

import pkg from './package.json' with { type: 'json' }
console.log(pkg)

Actual Behavior

import pkg from './package.json' assert {
                                 ^^^^^^

SyntaxError: Unexpected identifier 'assert'

Specifications

  • ts-node version: 10.9.2
  • node version: 22.1.0
  • TypeScript version: 5.3.3
  • @swc/core 1.4.17

Note

Node.js 22 removed import asserts and now only has import attributes. Setting emitAssertForImportAttributes to false in dist/transpilers/swc.js fixes the issue, but ofc, this would break the existing users, so not sure how to approach this!? A config option..? A breaking change?

Activity

  1. vocafeuvre commented on Jul 30, 2024

    @vocafeuvre

    Can confirm this behavior too. I'm using AdonisJS, which uses SWC under the hood to execute TS files.

    My workaround was to disable SWC, at the cost of waiting a couple extra seconds for my script to finish executing.

  2. mohd-akram commented on Feb 4, 2025

    @mohd-akram

    Running into this too. That line should be removed.

    @cspotcode @blakeembrey

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