nextjs - 💡(How to fix) Fix [Turbopack] TypeScript Namespace Merging causes ReferenceError during runtime [1 comments, 2 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#89136Fetched 2026-04-08 02:03:18
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Timeline (top)
labeled ×2commented ×1cross-referenced ×1issue_type_added ×1

Error Message

a is not defined at <unknown> (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr[root-of-the-server]__e206981a..js:23:14) at module evaluation (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr[root-of-the-server]__e206981a..js:24:3) at module evaluation (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr[root-of-the-server]e206981a..js:44:138) at module evaluation (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr[root-of-the-server]__e206981a..js:59:47) at Array.TURBOPACK__page$23$5 (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr\1e749_next_dist_185248fe..js:2670:62) at async doRender (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr\1e749_next_dist_185248fe..js:3065:28) at async handleResponse (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr\1e749_next_dist_185248fe..js:3271:32) at async Module.handler (file://C:\Playground\turbopack_issue\client.next\dev\server\chunks\ssr\1e749_next_dist_185248fe..js:3642:20)

Next.js version: 16.1.6 (Turbopack)

Code Example

## Error Type
Runtime ReferenceError

## Error Message
a is not defined
    at <unknown> (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:23:14)
    at module evaluation (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:24:3)
    at module evaluation (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:44:138)
    at module evaluation (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:59:47)
    at Array.__TURBOPACK__page__$23$5__ (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:2670:62)
    at async doRender (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:3065:28)
    at async handleResponse (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:3271:32)
    at async Module.handler (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:3642:20)

Next.js version: 16.1.6 (Turbopack)

---

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Education
  Available memory (MB): 16237
  Available CPU cores: 12
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
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/A

---

/* - RUNTIME FAIL - */
export namespace Test {
    export const a = 1;
}

export namespace Test {
    export const b = a + 1;
}

/* - 1. WORKS - */

// export namespace Test {
//     export const a = 1;
// }

// export namespace Test {
//     export const b = Test.a + 1;
// }
   
/* - 2. WORKS - */
// export namespace Test {
//     export const a = 1;
//     export const b = a + 1;
// }
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/rubenferreira97/turbopack_issue/tree/turbopack-namespace

To Reproduce

  1. Start next dev
  2. Go to localhost:3000
  3. See crash

Current vs. Expected behavior

Current Behavior:

Following error:

## Error Type
Runtime ReferenceError

## Error Message
a is not defined
    at <unknown> (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:23:14)
    at module evaluation (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:24:3)
    at module evaluation (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:44:138)
    at module evaluation (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\[root-of-the-server]__e206981a._.js:59:47)
    at Array.__TURBOPACK__page__$23$5__ (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:2670:62)
    at async doRender (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:3065:28)
    at async handleResponse (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:3271:32)
    at async Module.handler (file://C:\Playground\turbopack_issue\client\.next\dev\server\chunks\ssr\1e749_next_dist_185248fe._.js:3642:20)

Next.js version: 16.1.6 (Turbopack)

Expected Behavior:

Should run/compile just fine.

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Education
  Available memory (MB): 16237
  Available CPU cores: 12
Binaries:
  Node: 25.2.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: N/A
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/A

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

Turbopack

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

next dev (local)

Additional context

Minimal Reproduction:

/* - RUNTIME FAIL - */
export namespace Test {
    export const a = 1;
}

export namespace Test {
    export const b = a + 1;
}

/* - 1. WORKS - */

// export namespace Test {
//     export const a = 1;
// }

// export namespace Test {
//     export const b = Test.a + 1;
// }
   
/* - 2. WORKS - */
// export namespace Test {
//     export const a = 1;
//     export const b = a + 1;
// }

extent analysis

TL;DR

The issue can be resolved by ensuring that namespace variables are accessed correctly, likely by using the fully qualified namespace path.

Guidance

  • The error message "a is not defined" suggests that the variable a is not in scope when trying to access it in the namespace Test.
  • The provided minimal reproduction code shows that the issue occurs when trying to access a directly in the same namespace, but works when accessing it via the fully qualified namespace path Test.a.
  • To fix the issue, update the code to use the fully qualified namespace path when accessing variables within the same namespace.
  • Verify that the fix works by running next dev and checking that the error no longer occurs.

Example

export namespace Test {
    export const a = 1;
}

export namespace Test {
    export const b = Test.a + 1; // Use fully qualified namespace path
}

Notes

  • The issue seems to be related to how Turbopack handles namespace variables in the provided Next.js version.
  • The fix may not be necessary in other environments or versions of Next.js.

Recommendation

Apply workaround: Update the code to use fully qualified namespace paths when accessing variables within the same namespace, as shown in the example above. This should resolve the issue without requiring any version upgrades or configuration changes.

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