nextjs - 💡(How to fix) Fix Next SWC Jest transform incorrectly rewrites import attribute keyword in ESM mode [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#87143Fetched 2026-04-08 02:07:40
View on GitHub
Comments
1
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
commented ×1issue_type_added ×1labeled ×1

Root Cause

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".

Code Example

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
RAW_BUFFERClick to expand / collapse

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

extent analysis

TL;DR

Downgrade Node to a version that supports the "assert" keyword or wait for Next.js to update their transform code to use the "with" keyword.

Guidance

  • The issue is caused by Next.js' transform code replacing the "with" keyword with the oldassert keyword, which is not supported in Node 24.
  • To verify the issue, run the test with Node 24 and check for the SyntaxError: Unexpected identifier 'assert' error.
  • As a temporary workaround, consider downgrading Node to a version that supports the "assert" keyword.
  • Another possible solution is to wait for Next.js to update their transform code to use the "with" keyword, which would resolve the issue.

Example

No code snippet is provided as the issue is related to the interaction between Next.js and Node.js versions.

Notes

The issue is specific to the combination of Next.js version 16.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

nextjs - 💡(How to fix) Fix Next SWC Jest transform incorrectly rewrites import attribute keyword in ESM mode [1 comments, 1 participants]