remix-run/react-router · error · Error

Invalid route chunk name "${chunkName}" in "${id}"

Error message

Invalid route chunk name "${chunkName}" in "${id}"

What it means

Thrown in the route-chunk splitting `transform` hook (build mode only). React Router recognizes chunk module IDs of a specific shape via `isRouteChunkModuleId(id)` and then extracts a `chunkName` with `getRouteChunkNameFromModuleId(id)`. If the ID matched the chunk shape but `getRouteChunkNameFromModuleId` returned a falsy value (empty/undefined), the ID is malformed and splitting cannot proceed — a defensive guard against internal ID format drift.

Source

Thrown at packages/react-router-dev/vite/plugin.ts:2023

    },
    {
      name: "react-router:split-route-modules",
      async transform(code, id, options) {
        // Routes aren't chunked on the server
        if (options?.ssr) return;

        // Ignore anything not marked as a route chunk
        if (!isRouteChunkModuleId(id)) return;

        invariant(
          viteCommand === "build",
          "Route modules are only split in build mode",
        );

        let chunkName = getRouteChunkNameFromModuleId(id);

        if (!chunkName) {
          throw new Error(`Invalid route chunk name "${chunkName}" in "${id}"`);
        }

        let chunk = await getRouteChunkIfEnabled(
          cache,
          ctx,
          id,
          chunkName,
          code,
        );

        let preventEmptyChunkSnippet = ({ reason }: { reason: string }) =>
          `Math.random()<0&&console.log(${JSON.stringify(reason)});`;

        if (chunk === null) {
          return preventEmptyChunkSnippet({
            reason: "Split round modules disabled",
          });
        }

View on GitHub (pinned to 1fd704a7da)

Solutions

  1. Clear the build cache: `rm -rf node_modules/.react-router build/client build/server` and rebuild.
  2. Remove any custom Vite plugin that mutates virtual module IDs in the `react-router` namespace.
  3. Ensure all `@react-router/*` packages are on the same version (`pnpm why @react-router/dev`).
  4. Report the printed `id` if it persists — this path is normally unreachable.

Example fix

// before: build fails with "Invalid route chunk name"\n// after: clear cache and align versions\nrm -rf node_modules/.react-router build\npnpm update --filter "@react-router/*" --latest
Defensive patterns

Strategy: try-catch

Try / catch

// Wrap the build in a retry-once after clearing cache
import { rm } from "node:fs/promises";
try {
  await build(root, opts);
} catch (e) {
  if (/Invalid route chunk name/.test(String(e.message))) {
    await rm("node_modules/.react-router", { recursive: true, force: true });
    await build(root, opts);
  } else throw e;
}

Prevention

When it happens

Trigger: An internal virtual module ID that partially matches the chunk prefix but lacks the name segment; a custom Vite plugin that rewrites module IDs and strips the chunk name; React Router version skew between the main plugin and route-chunks helpers; a corrupted plugin cache from a previous interrupted build.

Common situations: Upgrading React Router across versions where the chunk ID format changed while stale cache remains; third-party plugins that alias or rewrite virtual module IDs; concurrent `react-router build` runs writing to the same `node_modules/.react-router` cache.

Related errors


AI-assisted analysis of remix-run/react-router@1fd704a7da (2026-08-12). Data as JSON: /api/errors/16d7019bc2974959. Report an issue: GitHub.