sveltejs/kit · error · Error
Server files not found at ${dir}, did you run `build` first?
Error message
Server files not found at ${dir}, did you run `build` first? What it means
Startup check in the preview server: it expects the build output at outDir/output/server (with a manifest.js) to exist before it can serve a production preview. This stackless error fires when vite preview runs before vite build, or when outDir was customized so the built server lives elsewhere.
Source
Thrown at packages/kit/src/exports/vite/preview/index.js:32
import { stackless } from '../../../utils/error.js';
/**
* @param {PreviewServer} vite
* @param {ValidatedConfig} svelte_config
*/
export async function preview(vite, svelte_config) {
const { paths } = svelte_config;
const base = paths.base;
const assets = paths.assets ? SVELTE_KIT_ASSETS : paths.base;
const protocol = vite.config.preview.https ? 'https' : 'http';
const etag = `"${Date.now()}"`;
const dir = join(svelte_config.outDir, 'output/server');
if (!fs.existsSync(`${dir}/manifest.js`)) {
throw stackless(`Server files not found at ${dir}, did you run \`build\` first?`);
}
const instrumentation = join(dir, 'instrumentation.server.js');
if (fs.existsSync(instrumentation)) {
await import(pathToFileURL(instrumentation).href);
}
/** @type {ServerInternalModule} */
const { set_assets } = await import(pathToFileURL(join(dir, 'internal.js')).href);
/** @type {ServerModule} */
const { Server } = await import(pathToFileURL(join(dir, 'index.js')).href);
/** @type {{ manifest: import('types').SSRManifest }} */
const { manifest } = await import(pathToFileURL(join(dir, 'manifest.js')).href);
set_assets(assets);
View on GitHub (pinned to 03f1687fe6)
Solutions
- Run `vite build` before `vite preview`
- Ensure the preview outDir matches the build outDir in the SvelteKit/Vite config
- Rebuild after changing config so output/server/manifest.js is regenerated
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/kit/src/exports/vite/preview/index.js:32 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/61ca54addf357cb6.
Report an issue: GitHub.