-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
Link to the code that reproduces this issue
https://github.com/nlwillia/import-attributes
To Reproduce
- npm install
- npm run test
- Note that the test has failed with
SyntaxError: Unexpected identifier 'assert'in the log. - node app/index.ts
- Note that the import is resolved and a result prints.
Current vs. Expected behavior
My project uses import attributes which originally used the keyword "assert" but have since changed to use the keyword "with". Node 24 does not support the keyword "assert".
The modern "with" syntax works in typescript code in a Next app, but it is failing in a Jest-based test because Next is inserting its own transform based on SWC, and when tests are run in ESM mode Next's forced config is setting an experimental option emitAssertForImportAttributes: true that replaces the "with" keyword with the old "assert".
The relevant line in Next's transform code is here. There's no way to supersede this option that I can see. Adding a .swcrc file doesn't help.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Available memory (MB): 65448
Available CPU cores: 16
Binaries:
Node: 24.11.1
npm: 11.6.2
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 16.1.0-canary.20 // Latest available version is detected (16.1.0-canary.20).
eslint-config-next: N/A
react: 19.2.2
react-dom: 19.2.2
typescript: 5.9.3
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
Testing
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
Rough stack of where the hardwired transform SWC options are hit.
getBaseSWCOptions(), options.ts:116
getBaseSWCOptions(), options.ts:327
process(), jest-transformer.ts:87
transformSourceAsync(), index.js:462
processTicksAndRejections(), task_queues:103
Async call from await
_transformAndBuildScriptAsync(), index.js:488
transformAsync(), index.js:542
transformFileAsync(), index.js:1302
loadEsmModule(), index.js:503
unstable_importModule(), index.js:694
processTicksAndRejections(), task_queues:103
Async call from await
jestAdapter(), runner.js:82
processTicksAndRejections(), task_queues:103
Async call from await
runTestInternal(), index.js:275
processTicksAndRejections(), task_queues:103
Async call from await
processTicksAndRejections(), task_queues:103
Async call from await
processTicksAndRejections(), task_queues:103
Async call from await
processTicksAndRejections(), task_queues:103
Async call from await
runTest(), index.js:343
anonymous(), index.js:499
processTicksAndRejections(), task_queues:103
Async call from await
processTicksAndRejections(), task_queues:103
Async call from Promise.then
anonymous(), index.js:494
anonymous(), index.js:23
run(), index.js:23
anonymous(), index.js:45
processTicksAndRejections(), task_queues:103
Async call from await
enqueue(), index.js:47
anonymous(), index.js:51
generator(), index.js:50
anonymous(), index.js:494
#createInBandTestRun(), index.js:494
runTests(), index.js:489
scheduleTests(), index.js:1140
processTicksAndRejections(), task_queues:103