SSR build: two chunks import each other, and a `var` is read before its chunk assigns it, so every server render fails (TanStack Start, node-server)

Open
#4,770 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
node.js, typescript, vite

Research direction

Start by tracing the server build configuration for the default node-server preset and how Nitro invokes Rolldown for SSR chunks. Check whether that build sets strictExecutionOrder, using issues #4605 and #4533 as related context. Done when the reported mutually importing chunks preserve initialization order and the affected server render succeeds; the issue does not name a test or a reduced reproduction.

Written by the indexing model from the issue text.

Description

rolldown tanstack vite
Environment
  • nitro 3.0.260903-beta (npm latest on 2026-10-13), Nitro's rolldown 1.2.13
  • vite 8.2.2
  • @tanstack/react-start 1.168.61, @tanstack/react-router 1.170.42
  • Build on Node 24.14.1 (macOS arm64); runs in node:24-bookworm-slim
  • Preset: default (node-server)
  • Config: nitro({ plugins: ['./src/nitro-startup.ts'] })
Reproduction

The app is private and I have not reduced it to a small public repository
yet. The two chunks and the lines that matter are below.

Describe the bug

vite build succeeds and the server starts with no error. .output/server/_ssr/
has two chunks that import each other:

  • router-BFTpZbpG2.mjs:20: import { router_exports } from "./router-BFTpZbpG.mjs"; (and re-exports router_exports)
  • router-BFTpZbpG.mjs:81: import { …, ServiceDeskIcon, … } from "./router-BFTpZbpG2.mjs";

The SSR entry loads router-BFTpZbpG2.mjs first (ssr.mjs:8690,
import("./router-BFTpZbpG2.mjs").then((n) => n.router_exports)). ESM runs its dependency
router-BFTpZbpG.mjs first, and that chunk's import back from
router-BFTpZbpG2.mjs is the cycle, so it runs before
router-BFTpZbpG2.mjs:1094 has run:

var ServiceDeskIcon = sidebarIcon("ServiceDesk", …)

router-BFTpZbpG.mjs:3171 then stores the binding's value, which is still
undefined (a var, so no error is thrown):

var SERVICE_DESK = { id: "service-desk", label: "Service Desk", icon: ServiceDeskIcon, Nav: ServiceDeskNav };

The value stays undefined for the life of the process, and React throws on
every server render that draws it:

Error in renderToReadableStream: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.

There is no cycle in the source. The module that defines ServiceDeskIcon
imports only React's types and a cn helper. A Node script that imports the
built router_exports and reads each route's product finds every icon
undefined.

inlineDynamicImports: true fixes it (one server file, each module runs its
imports first).

Additional context

Possibly related: #4605 (helpers placed after their first use in an SSR
chunk) and #4533 (an SSR chunk exports an undeclared name; same workaround).
Rolldown's docs say automatic code splitting "sometimes places modules
without respecting their original order"; Rolldown's strictExecutionOrder
addresses that, but Nitro does not set it for the server build.

Dominant language
TypeScript
Stars
11.5k
Forks
968
Avg merge
4d 9h
Merged PRs (30d)
64

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nitrojs/nitro

All issues in nitrojs/nitro

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.