Skip to content

[Turbopack] TypeScript Namespace Merging causes ReferenceError during runtime #89136

@rubenferreira97

Description

@rubenferreira97

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;
// }

Metadata

Metadata

Assignees

No one assigned

    Labels

    SWCRelated to minification/transpilation in Next.js.TurbopackRelated to Turbopack with Next.js.

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions