nextjs - ✅(Solved) Fix SWC minifier fails to rename closure parameters when called 3+ times causing ReferenceError [1 pull requests, 3 comments, 3 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#83925Fetched 2026-04-08 02:21:11
View on GitHub
Comments
3
Participants
3
Timeline
11
Reactions
1
Timeline (top)
commented ×3cross-referenced ×3subscribed ×2issue_type_added ×1

Error Message

Error occurred prerendering page "/". ReferenceError: range is not defined at <unknown> (.next/server/app/page.js)

Fix Action

Fix / Workaround

Current workarounds:

  1. Refactor to avoid closures referencing parent parameters
  2. Limit closure calls to 2 or fewer
  3. Use Next.js 15.4.0 or earlier

PR fix notes

PR #11101: Failing test for incomplete inlined function calls

Description (problem / solution / changelog)

Failing test for https://github.com/vercel/next.js/issues/83925

Changed files

  • crates/swc_ecma_minifier/tests/fixture/issues/react/hooks/6/input.js (added, +16/-0)
  • crates/swc_ecma_minifier/tests/fixture/issues/react/hooks/6/output.js (added, +1/-0)

Code Example

Error occurred prerendering page "/". 
ReferenceError: range is not defined
    at <unknown> (.next/server/app/page.js)

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:06 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.19.4
  npm: 10.8.2
  Yarn: 1.22.17
  pnpm: 10.13.1
Relevant Packages:
  next: 15.6.0-canary.12 // Latest available version is detected (15.6.0-canary.12).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.9.2
Next.js Config:
  output: N/A

---

const decideZoomByAccuracy = (range: number): number => {
  const isUnder = (accuracy: number): boolean => {
    return range <= accuracy;  // 'range' is not renamed in minified output
  };
  
  if (isUnder(0)) return 15;
  if (isUnder(50)) return 15;
  if (isUnder(100)) return 15;  // 3rd call triggers the bug!
  return 11;
};
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/SiroSuzume/next-build-bug-example

To Reproduce

  1. Clone the repository above
  2. Install dependencies with pnpm install (or npm install)
  3. Run the production build with pnpm build
  4. Observe the build fails with "ReferenceError: range is not defined" during prerendering

Current vs. Expected behavior

Current behavior: Following the reproduction steps, the build fails with:

Error occurred prerendering page "/". 
ReferenceError: range is not defined
    at <unknown> (.next/server/app/page.js)

The SWC minifier incorrectly transforms closures when they're called 3 or more times. The parameter range is renamed in the function signature but NOT in the closure body, causing the reference error.

Expected behavior: The build should complete successfully. The minifier should properly rename all references to the range parameter throughout the closure, regardless of how many times the closure is called.

Key finding:

  • With 2 closure calls: Build succeeds ✅
  • With 3+ closure calls: Build fails with ReferenceError ❌

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.3.0: Thu Jan  2 20:24:06 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 20.19.4
  npm: 10.8.2
  Yarn: 1.22.17
  pnpm: 10.13.1
Relevant Packages:
  next: 15.6.0-canary.12 // Latest available version is detected (15.6.0-canary.12).
  eslint-config-next: N/A
  react: 19.1.1
  react-dom: 19.1.1
  typescript: 5.9.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

SWC

Which stage(s) are affected? (Select all that apply)

next build (local), Vercel (Deployed)

Additional context

Pinpointed version where bug was introduced:

  • Last working version: Next.js 15.4.0 ✅
  • First broken version: Next.js 15.4.1 ❌ (when SWC was updated to v1.11.24)
  • Still broken in: 15.4.3, 15.5.3, 15.6.0-canary.12

The specific code pattern that triggers the bug:

const decideZoomByAccuracy = (range: number): number => {
  const isUnder = (accuracy: number): boolean => {
    return range <= accuracy;  // 'range' is not renamed in minified output
  };
  
  if (isUnder(0)) return 15;
  if (isUnder(50)) return 15;
  if (isUnder(100)) return 15;  // 3rd call triggers the bug!
  return 11;
};

Repository structure:

  • app/page.tsx - Reproduces the bug (3 closure calls → fails)
  • app/working-example.tsx - Demonstrates it works with 2 calls

Important findings:

  1. Setting serverMinification: false does NOT fix the issue
  2. The bug only occurs when the closure is called 3 or more times
  3. With exactly 2 calls, the build succeeds
  4. The issue affects both local builds and Vercel deployments

Current workarounds:

  1. Refactor to avoid closures referencing parent parameters
  2. Limit closure calls to 2 or fewer
  3. Use Next.js 15.4.0 or earlier

extent analysis

TL;DR

The most likely fix is to refactor the code to avoid closures referencing parent parameters or limit closure calls to 2 or fewer, as the SWC minifier incorrectly transforms closures when they're called 3 or more times.

Guidance

  • Identify and refactor code patterns that use closures referencing parent parameters, such as the decideZoomByAccuracy function, to avoid the minification issue.
  • Limit closure calls to 2 or fewer to prevent the SWC minifier from incorrectly transforming the code.
  • Consider using Next.js 15.4.0 or earlier as a temporary workaround, but be aware that this may introduce other compatibility issues.
  • Review the app/page.tsx and app/working-example.tsx files in the provided repository to understand the code pattern that triggers the bug and how to refactor it.

Example

// Refactored code to avoid closures referencing parent parameters
const decideZoomByAccuracy = (range: number): number => {
  const accuracyChecks = [0, 50, 100];
  for (const accuracy of accuracyChecks) {
    if (range <= accuracy) return 15;
  }
  return 11;
};

Notes

The provided code pattern and repository structure suggest that the issue is specific to the SWC minifier and its handling of closures. Refactoring the code to avoid this pattern or limiting closure calls should resolve the issue. However, this may require significant changes to the codebase.

Recommendation

Apply a workaround by refactoring the code to avoid closures referencing parent parameters, as this is a more sustainable solution than downgrading to an earlier version of Next.js. This approach will also make the code more maintainable and less prone to similar issues in the future.

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 - ✅(Solved) Fix SWC minifier fails to rename closure parameters when called 3+ times causing ReferenceError [1 pull requests, 3 comments, 3 participants]