{"record":{"id":"b8b84f7c20c0d2ef","repo":"withastro/astro","slug":"the-server-entrypoint-fileurltopath-preview-serv","errorCode":null,"errorMessage":"The server entrypoint ${fileURLToPath(preview.serverEntrypoint)} does not exist. Have you ran a build yet?","messagePattern":"The server entrypoint (.+?) does not exist\\. Have you ran a build yet\\?","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"critical","filePath":"packages/integrations/node/src/preview.ts","lineNumber":27,"sourceCode":"\nconst createPreviewServer: CreatePreviewServer = async (preview) => {\n\tlet ssrHandler: ServerModule['handler'];\n\ttry {\n\t\tprocess.env.ASTRO_NODE_AUTOSTART = 'disabled';\n\t\tconst ssrModule: MaybeServerModule = await import(preview.serverEntrypoint.toString());\n\t\tif (typeof ssrModule.handler === 'function') {\n\t\t\tssrHandler = ssrModule.handler;\n\t\t} else {\n\t\t\tthrow new AstroError(\n\t\t\t\t`The server entrypoint doesn't have a handler. Are you sure this is the right file?`,\n\t\t\t);\n\t\t}\n\t} catch (err) {\n\t\tif (\n\t\t\t(err as any).code === 'ERR_MODULE_NOT_FOUND' &&\n\t\t\t(err as any).url === preview.serverEntrypoint.href\n\t\t) {\n\t\t\tthrow new AstroError(\n\t\t\t\t`The server entrypoint ${fileURLToPath(\n\t\t\t\t\tpreview.serverEntrypoint,\n\t\t\t\t)} does not exist. Have you ran a build yet?`,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow err;\n\t\t}\n\t}\n\t// If the user didn't specify a host, it will already have been defaulted to\n\t// \"localhost\" by getResolvedHostForHttpServer in astro core/preview/util.ts.\n\t// The value `undefined` actually means that either the user set `options.server.host`\n\t// to `true`, or they passed `--host` without an argument. In that case, we\n\t// should listen on all IPs.\n\tconst host = process.env.HOST ?? preview.host ?? '0.0.0.0';\n\n\tconst port = preview.port ?? 4321;\n\tconst server = createServer(ssrHandler, host, port);\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/integrations/node/src/preview.ts#L9-L45","documentation":"Thrown by the @astrojs/node preview server when Node's dynamic `import()` of the server entry fails with `ERR_MODULE_NOT_FOUND` for the exact `serverEntrypoint` URL. It means the built server bundle file is not on disk where preview expects it.","triggerScenarios":"Running `astro preview` before `astro build`, or after deleting/moving `dist/`. The preview server resolves `preview.serverEntrypoint` (typically `dist/server/entry.mjs`) and the file is absent.","commonSituations":"Fresh clone where only sources are present. A `clean`/`rimraf dist` step run between build and preview. Wrong `outDir`/`build.server` config so the file lands elsewhere.","solutions":["Run `astro build` first, then `astro preview`.","Confirm `build.server` and `outDir` in `astro.config` resolve to the directory you are previewing from.","Check that no `.gitignore`/CI cleanup removed `dist/` after the build step."],"exampleFix":"# before\nastro preview   # without a prior build\n# after\nastro build && astro preview","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nimport { fileURLToPath } from 'node:url';\nconst entry = fileURLToPath(serverEntrypoint);\nif (!existsSync(entry)) {\n  throw new Error(`Build output missing: ${entry}. Run 'astro build' first.`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make `astro preview` always depend on a successful build in scripts/CI.","Don't delete `dist/` between build and preview.","Keep `outDir`/`build.server` stable across the two commands."],"tags":["node-adapter","preview","build-output","filesystem"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}