TypeStrong / ts-node

TypeScript execution and REPL for node.js
https://typestrong.org/ts-node
MIT License
12.86k stars 536 forks source link

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

Open KidkArolis opened 5 months ago

KidkArolis commented 5 months ago

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

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?

vocafeuvre commented 2 months ago

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.