{"record":{"id":"2dac8fdefe14715f","repo":"remix-run/react-router","slug":"error-splitting-route-module-id-name-th-2dac8f","errorCode":null,"errorMessage":"Error splitting route module: ${id}\n\n- ${name}\n\nThis export could not be split into its own chunk because it shares code with other exports. You should extract any shared code into its own module and then import it within the route module.","messagePattern":"Error splitting route module: (.+?)\n\n- (.+?)\n\nThis export could not be split into its own chunk because it shares code with other exports\\. You should extract any shared code into its own module and then import it within the route module\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/react-router-dev/vite/rsc/virtual-route-modules.ts","lineNumber":550,"sourceCode":"\nfunction validateRouteChunks({\n  id,\n  valid,\n}: {\n  id: string;\n  valid: Record<Exclude<RouteChunkName, \"main\">, boolean>;\n}): void {\n  let invalidChunks = Object.entries(valid)\n    .filter(([_, isValid]) => !isValid)\n    .map(([chunkName]) => chunkName);\n\n  if (invalidChunks.length === 0) {\n    return;\n  }\n\n  let plural = invalidChunks.length > 1;\n\n  throw new Error(\n    [\n      `Error splitting route module: ${id}`,\n\n      invalidChunks.map((name) => `- ${name}`).join(\"\\n\"),\n\n      `${plural ? \"These exports\" : \"This export\"} could not be split into ${\n        plural ? \"their own chunks\" : \"its own chunk\"\n      } because ${\n        plural ? \"they share\" : \"it shares\"\n      } code with other exports. You should extract any shared code into its own module and then import it within the route module.`,\n    ].join(\"\\n\\n\"),\n  );\n}\n","sourceCodeStart":532,"sourceCodeEnd":564,"githubUrl":"https://github.com/remix-run/react-router/blob/6beaca39526d5716c3c112ebb0782765baa5a9ce/packages/react-router-dev/vite/rsc/virtual-route-modules.ts#L532-L564","documentation":"In RSC mode the Vite plugin splits each route module into separate chunks per export (loader, action, Component, clientLoader, ...) so server-only code never ships to the client. After splitting it validates that each export landed in its own chunk; when an export could not be isolated because it shares module-scope code (helpers, constants, instantiated clients) with other exports, the build fails naming the offending exports and telling you to extract the shared code into its own module.","triggerScenarios":"A route module declares a helper or constant at module top level that is referenced from two or more special exports — e.g. 'const db = createDb()' used by both 'loader' and 'clientLoader', or a shared 'loadPost()' function — so the splitter cannot separate the chunks.","commonSituations":"Writing loader + clientLoader pairs that share a local data function; refactoring that hoists shared constants into the route module; moving server client instantiation into the route file for convenience.","solutions":["Move the shared code into its own file (e.g. app/routes/post.data.ts) and import it from the route module","If one of the exports is unnecessary (e.g. you don't need clientLoader), remove it so no split is required","Re-run 'react-router build' — validation happens per route module, so fix routes one at a time as listed"],"exampleFix":"// before — app/routes/posts.$slug.tsx\nasync function loadPost(slug: string) { /* shared by both exports */ }\nexport async function loader({ params }) { return loadPost(params.slug); }\nexport async function clientLoader({ params }) { return loadPost(params.slug); }\n\n// after — app/posts.shared.ts\nexport async function loadPost(slug: string) { /* ... */ }\n\n// app/routes/posts.$slug.tsx\nimport { loadPost } from \"../posts.shared\";\nexport async function loader({ params }) { return loadPost(params.slug); }\nexport async function clientLoader({ params }) { return loadPost(params.slug); }","handlingStrategy":"validation","validationCode":"// no cheap pre-check exists — use the build itself as the validator in CI\n// .github/workflows/ci.yml\n// - run: pnpm install --frozen-lockfile\n// - run: pnpm build   # the RSC splitter validates every route module here","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never share module-scope helpers between two special exports in a route module — put them in a separate file","Instantiate server clients (db, CMS) in their own module and import them","Fix splitter errors immediately; they name the exact exports that could not be isolated"],"tags":["rsc","code-splitting","route-module","build","refactor"],"backgroundTag":"code-splitting-conflict","analyzedSha":"6beaca39526d5716c3c112ebb0782765baa5a9ce","analyzedAt":"2026-08-18T18:04:14.938Z","contentChangedAt":"2026-08-18T18:04:14.938Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}