-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Open
Open
Copy link
Labels
SWCRelated to minification/transpilation in Next.js.Related to minification/transpilation in Next.js.
Description
Link to the code that reproduces this issue
https://github.com/canyon-project/nextjs16-swc-duplicate-compilation
To Reproduce
- pnpm i
- npm run build
- look .swc-plugin-stage-output
Current vs. Expected behavior
After testing the Next.js + Turbopack combination, we observed duplicate identical filenames appearing in the SWC AST during compilation. Our investigation identified that this behavior is inherent to Next.js' compilation workflow.
To address this ambiguity (consistent with Vite's pattern), we propose appending a layer query parameter to the filename passed to SWC (via TransformContext) — e.g., app/page.tsx?layer=app-rsc — to enable SWC plugins to distinguish between these duplicate entries.
For extensibility (aligned with next-swc-loader), we use a named parameter format:
- Use
?layer=valuefor paths with no existing query string - Use
&layer=...for paths that already contain a query string
Expected behavior
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
Available memory (MB): 16384
Available CPU cores: 8
Binaries:
Node: 25.2.1
npm: 11.6.2
Yarn: N/A
pnpm: 10.13.0
Relevant Packages:
next: 16.1.6 // Latest available version is detected (16.1.6).
eslint-config-next: N/A
react: 19.2.3
react-dom: 19.2.3
typescript: 5.9.3
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
SWC
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
SWCRelated to minification/transpilation in Next.js.Related to minification/transpilation in Next.js.