vercel / vercel/next.js

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

Open
#87,143 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Testing
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction repository and run npm install, npm run test, and node app/index.ts to compare Jest with direct Node behavior. Read packages/next/src/build/swc/options.ts around lines 116 and 128, then follow the Jest path through jest-transformer.ts:87. Done means the ESM Jest test accepts the modern "with" import attribute and passes on Node 24 without rewriting it to "assert".

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, typescript
Domain
build-system, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.