{"record":{"id":"2066a2f391b12e3c","repo":"remix-run/react-router","slug":"module-cannot-have-both-a-layout-export-and-a-serv","errorCode":null,"errorMessage":"Module cannot have both a Layout export and a ServerLayout export","messagePattern":"Module cannot have both a Layout export and a ServerLayout export","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-router-dev/vite/rsc/virtual-route-config.ts","lineNumber":32,"sourceCode":"  let code = js`import * as React from \"react\";\nfunction frameworkRoute(lazy) {\n  return async () => {\n    const mod = await lazy();\n    let Component;\n    let Layout;\n    let ErrorBoundary;\n    let HydrateFallback;\n    if (\"default\" in mod && mod.default) {\n      if (\"ServerComponent\" in mod && mod.ServerComponent) {\n        throw new Error(\"Module cannot have both a default export and a ServerComponent export\");\n      }\n      Component = mod.default;\n    } else if (\"ServerComponent\" in mod && mod.ServerComponent) {\n      Component = mod.ServerComponent;\n    }\n    if (\"Layout\" in mod && mod.Layout) {\n      if (\"ServerLayout\" in mod && mod.ServerLayout) {\n        throw new Error(\"Module cannot have both a Layout export and a ServerLayout export\");\n      }\n      Layout = mod.Layout;\n    } else if (\"ServerLayout\" in mod && mod.ServerLayout) {\n      Layout = mod.ServerLayout;\n    }\n    if (\"ErrorBoundary\" in mod && mod.ErrorBoundary) {\n      if (\"ServerErrorBoundary\" in mod && mod.ServerErrorBoundary) {\n        throw new Error(\n          \"Module cannot have both an ErrorBoundary export and a ServerErrorBoundary export\",\n        );\n      }\n      ErrorBoundary = mod.ErrorBoundary;\n    } else if (\"ServerErrorBoundary\" in mod && mod.ServerErrorBoundary) {\n      ErrorBoundary = mod.ServerErrorBoundary;\n    }\n    if (\"HydrateFallback\" in mod && mod.HydrateFallback) {\n      if (\"ServerHydrateFallback\" in mod && mod.ServerHydrateFallback) {\n        throw new Error(","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/remix-run/react-router/blob/1fd704a7dabcbe3ae09d7387b460e6acaba30ec1/packages/react-router-dev/vite/rsc/virtual-route-config.ts#L14-L50","documentation":"Runtime guard in frameworkRoute() (virtual-route-config.ts): a route module cannot export both `Layout` (client) and `ServerLayout` (server). The wrapper picks one Layout slot; exporting both is ambiguous. Thrown at module-load time inside the lazy route resolver.","triggerScenarios":"A layout route module (e.g. app/routes/_layout.tsx) exports both `Layout` and `ServerLayout`. The `if ('Layout' in mod && mod.Layout)` branch detects the coexistence and throws.","commonSituations":"Splitting a layout into client/server variants and leaving both exports. Migrating a Framework Mode layout to RSC Framework Mode without removing the client Layout.","solutions":["Keep only one Layout export per module: `Layout` for client-rendered layouts, or `ServerLayout` for server-rendered layouts.","If you need both behaviors, split into two route modules or use a shared child component imported by each.","Regenerate types to get the build-time duplicate check."],"exampleFix":"// app/routes/_layout.tsx\n// before\nexport function Layout({ children }) { return <div className=\"client\">{children}</div>; }\nexport function ServerLayout({ children }) { return <div className=\"server\">{children}</div>; }\n// after (server layout only)\nexport function ServerLayout({ children }) { return <div className=\"server\">{children}</div>; }","handlingStrategy":"validation","validationCode":"const src = readFileSync(layoutFile, 'utf8');\nconst hasLayout = /export\\s+(async\\s+)?function\\s+Layout\\b/.test(src);\nconst hasServerLayout = /export\\s+(async\\s+)?function\\s+ServerLayout\\b/.test(src);\nif (hasLayout && hasServerLayout) throw new Error(`${layoutFile}: cannot export both Layout and ServerLayout`);","typeGuard":"function moduleExportsOnlyOneLayout(mod: Record<string, unknown>): boolean {\n  return !mod.Layout || !mod.ServerLayout;\n}","tryCatchPattern":null,"preventionTips":["Pick one layout export per module; document the choice in a comment.","Use typegen to catch duplicates before runtime."],"tags":["rsc","route-module","exports","layout"],"backgroundTag":null,"analyzedSha":"1fd704a7dabcbe3ae09d7387b460e6acaba30ec1","analyzedAt":"2026-08-12T13:54:57.804Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}