Skip to content

Next SWC Jest transform incorrectly rewrites import attribute keyword in ESM mode #87143

@nlwillia

Description

@nlwillia

Link to the code that reproduces this issue

https://github.com/nlwillia/import-attributes

To Reproduce

  1. npm install
  2. npm run test
  3. Note that the test has failed with SyntaxError: Unexpected identifier 'assert' in the log.
  4. node app/index.ts
  5. 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/A

Which 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    TestingRelated to testing with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions