{"record":{"id":"16d7019bc2974959","repo":"remix-run/react-router","slug":"invalid-route-chunk-name-chunkname-in-id","errorCode":null,"errorMessage":"Invalid route chunk name \"${chunkName}\" in \"${id}\"","messagePattern":"Invalid route chunk name \"(.+?)\" in \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-router-dev/vite/plugin.ts","lineNumber":2023,"sourceCode":"    },\n    {\n      name: \"react-router:split-route-modules\",\n      async transform(code, id, options) {\n        // Routes aren't chunked on the server\n        if (options?.ssr) return;\n\n        // Ignore anything not marked as a route chunk\n        if (!isRouteChunkModuleId(id)) return;\n\n        invariant(\n          viteCommand === \"build\",\n          \"Route modules are only split in build mode\",\n        );\n\n        let chunkName = getRouteChunkNameFromModuleId(id);\n\n        if (!chunkName) {\n          throw new Error(`Invalid route chunk name \"${chunkName}\" in \"${id}\"`);\n        }\n\n        let chunk = await getRouteChunkIfEnabled(\n          cache,\n          ctx,\n          id,\n          chunkName,\n          code,\n        );\n\n        let preventEmptyChunkSnippet = ({ reason }: { reason: string }) =>\n          `Math.random()<0&&console.log(${JSON.stringify(reason)});`;\n\n        if (chunk === null) {\n          return preventEmptyChunkSnippet({\n            reason: \"Split round modules disabled\",\n          });\n        }","sourceCodeStart":2005,"sourceCodeEnd":2041,"githubUrl":"https://github.com/remix-run/react-router/blob/1fd704a7dabcbe3ae09d7387b460e6acaba30ec1/packages/react-router-dev/vite/plugin.ts#L2005-L2041","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Clear the build cache: `rm -rf node_modules/.react-router build/client build/server` and rebuild.","Remove any custom Vite plugin that mutates virtual module IDs in the `react-router` namespace.","Ensure all `@react-router/*` packages are on the same version (`pnpm why @react-router/dev`).","Report the printed `id` if it persists — this path is normally unreachable."],"exampleFix":"// 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","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Wrap the build in a retry-once after clearing cache\nimport { rm } from \"node:fs/promises\";\ntry {\n  await build(root, opts);\n} catch (e) {\n  if (/Invalid route chunk name/.test(String(e.message))) {\n    await rm(\"node_modules/.react-router\", { recursive: true, force: true });\n    await build(root, opts);\n  } else throw e;\n}","preventionTips":["Keep `@react-router/*` packages on a single shared version.","Don't run multiple `react-router build` invocations against the same cache directory concurrently.","Add a cache-clean step to CI before the build."],"tags":["route-chunks","build","cache","internal"],"backgroundTag":null,"analyzedSha":"1fd704a7dabcbe3ae09d7387b460e6acaba30ec1","analyzedAt":"2026-08-12T13:54:57.804Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}