{"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/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/astro/src/core/preview/index.ts#L36-L72","documentation":"`astro preview` serves the artifacts produced by `astro build`. For a static build (no adapter preview entrypoint), it starts a static file server rooted at the client output directory (`dist/client` by default) and first verifies it exists with `fs.existsSync`. If the directory is absent there is nothing to serve, so preview aborts and suggests running the build first.","triggerScenarios":"Running `astro preview` on a static site before `astro build` has ever emitted output; a build that failed partway before writing the client bundle; a custom `outDir`/`build.client` config that differs from where the build actually wrote; running preview from the wrong working directory so the relative outDir resolves elsewhere.","commonSituations":"Fresh clone where only `astro dev` was run; CI pipelines that separate build and preview stages and skip the build step; `dist/` removed by a clean task or `.gitignore` workflow; outDir changed in astro.config after the last build.","solutions":["Run `astro build` before `astro preview` (e.g. chain them: `astro build && astro preview`)","Verify `outDir` and `build.client` in astro.config match the directory preview expects","Run preview from the project root (where astro.config lives) so the relative outDir resolves correctly","If the build itself fails, fix the build errors first — preview cannot run without its output"],"exampleFix":"# before\nastro preview\n# after\nastro build && astro preview","handlingStrategy":"validation","validationCode":"// scripts/preview.mjs — gate preview on the build output existing\nimport { existsSync } from 'node:fs';\nimport { resolve } from 'node:path';\nconst clientOutDir = resolve('dist/client'); // must match build.client / outDir\nif (!existsSync(clientOutDir)) {\n  console.error(`Missing ${clientOutDir} — run \\`astro build\\` first`);\n  process.exit(1);\n}\n// then spawn `astro preview`","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chain build and preview in one npm script: `\"preview\": \"astro build && astro preview\"`","Keep `outDir`/`build.client` stable between builds and previews — re-run build after changing them","Run preview from the project root so the relative output directory resolves correctly","In CI, make the preview job depend on the build job or copy the dist artifact explicitly"],"tags":["preview","static-output","build","cli"],"backgroundTag":"missing-build-artifact","analyzedSha":"52e6c34790cc8ac4e69e6135ace06049867e5c4a","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}