{"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":"error","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/52e6c34790cc8ac4e69e6135ace06049867e5c4a/packages/integrations/node/src/preview.ts#L9-L45","documentation":"astro preview serves the result of the last astro build. The Node adapter imports the server entrypoint from disk and, when Node fails with ERR_MODULE_NOT_FOUND whose url matches preview.serverEntrypoint, it reports the missing file path and points you at running a build first.","triggerScenarios":"Running astro preview before astro build; dist/ (or the configured outDir) deleted or never created; outDir or build.server changed between build and preview so the entry path moved; a build that failed partway.","commonSituations":"Fresh clone or CI job that runs preview without build; switching adapters without rebuilding; scripts that clean output directories before preview.","solutions":["Run astro build, then astro preview","Confirm the entry file exists at the reported path (default dist/server/entry.mjs)","Rebuild after changing outDir, build.server, or the adapter so preview.serverEntrypoint matches the fresh output"],"exampleFix":"# before\nastro preview\n# after\nastro build && astro preview","handlingStrategy":"validation","validationCode":"import { existsSync } from 'node:fs';\nconst entry = 'dist/server/entry.mjs';\nif (!existsSync(entry)) {\n  console.error(`Missing ${entry}; run astro build first`);\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Chain build and preview: astro build && astro preview","Keep outDir and build.server identical between build and preview commands","Treat a missing server entry as a skipped/failed build, not a preview problem"],"tags":["node","preview","build-output","entrypoint"],"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"}