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

オープン 初心者向け
#8,839 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Sheraff がすでに取り組んでいます。

2026年10月25日 から。

  • #8817 @Sheraff による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, react, typescript, vite

調査の方向性

@tanstack/start-plugin-core/dist/esm/vite/start-router-plugin/plugin.js の config() フックから始めてください。そこでは new RegExp(resolvedGeneratedRouteTreePath) から clientTreePlugin.load.filter が設定されています。再現するには、パスに + を含むプロジェクトをビルドし、test(path) が false を返すことを確認します。フィルターがそのようなパス内の生成済みルートツリーに一致し、クライアントビルドがサーバーモジュールを外部化しなくなれば完了です。この issue では、同じパターンを確認する場所として rsbuild/watch-ignored.js も挙げられています。

索引モデルが issue の本文から書いたものです。

説明

information needed
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 name Peak memory "externalized for browser" warnings Result
refactor+server-function-auth >8.5 GB in 16s, still climbing 265 killed
refactor-server-function-auth 1.4 GB 0 ✓ 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
主要言語
TypeScript
スター
15.3k
フォーク
1.9k
平均マージ
20時間 30分
マージ済み PR(30日)
55

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/router のほかの issue

TanStack/router の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。