Skip to content
Source
Sign inSign up
TanStack/router

Start: a `+` in the project path leaks server code into the client build (unescaped `new RegExp(routeTreePath)`), and memory grows without limit #8839

Send to my agent
Closedjmherzo(GitHub profile, opens in a new tab) opened this issue 1 comment

Which project does this relate to?

Start

Describe the bug

start-plugin-core builds a RegExp from the absolute path of the generated route tree without escaping it:

// @tanstack/start-plugin-core/dist/esm/vite/start-router-plugin/plugin.js (1.171.54 and 1.171.55)
config() {
  resolvedGeneratedRouteTreePath = normalizePath(getGeneratedRouteTreePath());
  clientTreePlugin.load.filter = { id: { include: new RegExp(resolvedGeneratedRouteTreePath) } };
},

When the project path contains a regex metacharacter such as +, the pattern no longer matches its own file:

const p = "/x/refactor+server-function-auth/src/routeTree.gen.ts";
new RegExp(p).test(p); // false

So tanstack-start:route-tree-client-plugin never loads the route tree for the client environment, and pruneServerOnlySubtrees is skipped. The client build then pulls in server-only code. In my app that's firebase-admin, @grpc/grpc-js, google-auth-library and Node built-ins: 265 Module "…" has been externalized for browser compatibility warnings. The build process then keeps allocating memory until the OS kills it. I saw 98 GB, which filled the swap on an 18 GB Mac.

This is easy to hit now: Claude Code names git worktrees by replacing / in the branch name with +, e.g. .claude/worktrees/refactor+server-function-auth.

Steps to reproduce

  1. Create any TanStack Start app with a server function that imports a Node-only package.
  2. Put it in a folder whose name contains +, e.g. mv app app+test.
  3. Run vite build.
  4. Server modules show up in the client build and memory grows without limit. Rename the folder to app-test and the build is normal.

Measured on the same checkout and the same node_modules:

Folder namePeak memory"externalized for browser" warningsResult
refactor+server-function-auth>8.5 GB in 16s, still climbing265killed
refactor-server-function-auth1.4 GB0✓ built in 12s

Suggested fix

Escape the path before building the RegExp, e.g. new RegExp(escapeRegExp(resolvedGeneratedRouteTreePath)), or match on an exact id instead of a regex. A quick search found a few other new RegExp(...) calls built from values that could contain metacharacters, e.g. rsbuild/watch-ignored.js. They might be worth a look too.

Versions

  • @tanstack/react-start 1.169.3, @tanstack/start-plugin-core 1.171.54 (the same code is still in 1.171.55)
  • vite 8.3.4 (rolldown), nitro 3.0.260903-beta
  • Node 24, pnpm 11.1.1, macOS 26 (Darwin 27.2), Apple Silicon
  1. please provide a complete reproducer project

  2. schiller-manuel(GitHub profile, opens in a new tab) added labelsinformation needed

Sign in to join this conversation.