{"record":{"id":"5f2addb23c15d07c","repo":"withastro/astro","slug":"preview-the-output-directory-outdirpath-does","errorCode":null,"errorMessage":"[preview] The output directory ${outDirPath} does not exist. Did you run `astro build`?","messagePattern":"\\[preview\\] The output directory (.+?) does not exist\\. Did you run `astro build`\\?","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/astro/src/core/preview/index.ts","lineNumber":54,"sourceCode":"\n\tconst settings = await runHookConfigSetup({\n\t\tsettings: _settings,\n\t\tcommand: 'preview',\n\t\tlogger: logger,\n\t});\n\n\t// Create a route manifest and determine buildOutput from actual routes.\n\t// Route scanning sets settings.buildOutput to 'server' if any route is non-prerendered.\n\tsettings.buildOutput = getPrerenderDefault(settings.config) ? 'static' : 'server';\n\tawait createRoutesList({ settings: settings, cwd: inlineConfig.root }, logger);\n\n\tawait runHookConfigDone({ settings: settings, logger: logger, command: 'preview' });\n\n\tif (settings.buildOutput === 'static' && !settings.adapter?.previewEntrypoint) {\n\t\tconst clientOutDir = getClientOutputDirectory(settings);\n\t\tif (!fs.existsSync(clientOutDir)) {\n\t\t\tconst outDirPath = fileURLToPath(clientOutDir);\n\t\t\tthrow new Error(\n\t\t\t\t`[preview] The output directory ${outDirPath} does not exist. Did you run \\`astro build\\`?`,\n\t\t\t);\n\t\t}\n\t\tconst server = await createStaticPreviewServer(settings, logger);\n\t\treturn server;\n\t}\n\n\tif (!settings.adapter) {\n\t\tthrow new Error(`[preview] No adapter found.`);\n\t}\n\n\tif (!settings.adapter.previewEntrypoint) {\n\t\tthrow new Error(\n\t\t\t`[preview] The ${settings.adapter.name} adapter does not support the preview command.`,\n\t\t);\n\t}\n\t// We need to use require.resolve() here so that advanced package managers like pnpm\n\t// don't treat this as a dependency of Astro itself. This correctly resolves the","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/core/preview/index.ts#L36-L72","documentation":"Thrown by the preview command (createStaticPreviewServer path) when the build output directory does not exist on disk. Preview serves the already-built static assets, so if `astro build` was never run (or output went elsewhere), the client output directory is missing and preview cannot start.","triggerScenarios":"Running `astro preview` for a static (or prerender-default) build when the client output directory (default dist/client or dist) does not exist. The check fs.existsSync(clientOutDir) is false, so the error names the resolved outDirPath.","commonSituations":"Running preview before build; changing outDir in config so build output goes to a different folder than preview reads; CI/deploy workflows that run preview on a clean checkout without building; a failed/partial build that did not emit the client dir.","solutions":["Run `astro build` first, then `astro preview`.","Verify `outDir`/`build.client` in astro.config matches where build actually emits.","Ensure the build completed successfully (check for build errors) before previewing."],"exampleFix":"// before\nastro preview  # dist/ missing\n\n// after\nastro build && astro preview","handlingStrategy":"validation","validationCode":"// Verify build output exists before starting preview.\nimport { existsSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nconst clientDir = fileURLToPath(new URL('dist/client', import.meta.url));\nif (!existsSync(clientDir)) {\n  throw new Error('Run `astro build` before `astro preview`');\n}\n// then start preview","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run `astro build` before `astro preview`.","Verify outDir/build.client in config matches actual build output.","In CI, run build as a prerequisite step before preview."],"tags":["preview","build","static","cli","filesystem"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}