-
Notifications
You must be signed in to change notification settings - Fork 30k
Description
Link to the code that reproduces this issue
https://github.com/branderzhai/bug/tree/main/nextjs_swc_issue
To Reproduce
When building a project with the default Turbopack,SWC will re-compress the code of third‑party libraries during bundling. However, due to a bug in SWC, the compressed code becomes semantically inequivalent to the original.
I extracted the part of the real project where the error occurred, and the same issue can be reproduced. The reproduction steps are as follows.
nextjs_swc_issue.zip
Reproduce Steps
- unzip the demo.
- pnpm i
- pnpm build
- pnpm start
- clicking the button
Exception thrown, error in console.
Current vs. Expected behavior
As you can see, the original code (or use "pnpm dev" to run up the project) like below
However, after the SWC process, an internal method call was inlined into the main function, but its variable names were not handled correctly.

When I replaced the default build tool with webpack and terser, everything returned to normal.
Provide environment information
Operating System:
Platform: windows
Version: Windows 11
Binaries:
Node: 20.15.1
npm:10.9.0
pnpm:9.4.0
Relevant Packages:
"next": "16.0.4",
"react": "19.2.0",
"react-dom": "19.2.0"Which area(s) are affected? (Select all that apply)
Turbopack, SWC
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
No response