{"record":{"id":"73f5f692e428bff8","repo":"withastro/astro","slug":"unexpectedly-unable-to-find-a-component-instance-f","errorCode":null,"errorMessage":"Unexpectedly unable to find a component instance for route ${route.route}","messagePattern":"Unexpectedly unable to find a component instance for route (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/environment/dev-nonrunnable.ts","lineNumber":47,"sourceCode":"async function getModuleForRoute(\n\tmanifest: SSRManifest,\n\troute: RouteData,\n): Promise<SinglePageBuiltModule> {\n\tfor (const defaultRoute of getDefaultRoutes(manifest)) {\n\t\tif (route.component === defaultRoute.component) {\n\t\t\treturn {\n\t\t\t\tpage: () => Promise.resolve(defaultRoute.instance),\n\t\t\t};\n\t\t}\n\t}\n\n\tif (route.type === 'redirect') {\n\t\treturn RedirectSinglePageBuiltModule;\n\t} else {\n\t\tif (manifest.pageMap) {\n\t\t\tconst importComponentInstance = manifest.pageMap.get(route.component);\n\t\t\tif (!importComponentInstance) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Unexpectedly unable to find a component instance for route ${route.route}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn await importComponentInstance();\n\t\t} else if (manifest.pageModule) {\n\t\t\treturn manifest.pageModule;\n\t\t}\n\t\tthrow new Error(\n\t\t\t\"Astro couldn't find the correct page to render, probably because it wasn't correctly mapped for SSR usage. This is an internal error, please file an issue.\",\n\t\t);\n\t}\n}\n\nasync function getComponentByRoute(\n\tmanifest: SSRManifest,\n\trouteData: RouteData,\n): Promise<ComponentInstance> {\n\ttry {","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/withastro/astro/blob/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/core/environment/dev-nonrunnable.ts#L29-L65","documentation":"In the dev fallback (`dev-nonrunnable.ts`) route modules are looked up in `manifest.pageMap` keyed by `route.component`; a missing key means the internal routing manifest is out of sync with the requested route — an internal invariant violation, not a user configuration error. Redirect routes are handled before this check, so only mapped page routes reach it.","triggerScenarios":"Dev-time manifest desync: a page was renamed/moved/added while the running dev server still holds a stale manifest, or a race between file change and route collection left `pageMap` without an entry for the requested route.","commonSituations":"Renaming or bulk-moving files in `src/pages` while `astro dev` is running; an interrupted sync/HMR update; leftover processes from a previous session holding the lock.","solutions":["Restart the dev server so the route manifest is rebuilt from disk.","Stop stale servers first (`astro dev stop` or kill the process), then start again.","If it persists, delete the `.astro` cache directory and restart.","Still reproducible on latest versions? File an Astro issue with the route pattern and steps."],"exampleFix":"# before\nError: Unexpectedly unable to find a component instance for route /renamed-page\n\n# after — restart to rebuild the route manifest\npnpm -C . dev stop && pnpm -C . dev","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Tooling that drives the dev environment: a stale manifest recovers on restart\ntry {\n  await renderRoute(route);\n} catch (err) {\n  if (err instanceof Error && err.message.includes('component instance for route')) {\n    await restartDevServer(); // rebuilds pageMap from disk\n    return renderRoute(route);\n  }\n  throw err;\n}","preventionTips":["Restart the dev server after bulk renames/moves under src/pages.","Stop stale servers (`astro dev stop`) before starting a new one on the same root.","Report routes that reliably reproduce after a clean restart."],"tags":["internal","dev-server","routing","hmr"],"backgroundTag":"stale-dev-server-state","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}