{"record":{"id":"2a021f9b41b7cd5c","repo":"evanw/esbuild","slug":"cannot-serve-s-without-an-output-path","errorCode":null,"errorMessage":"Cannot serve %s without an output path","messagePattern":"Cannot serve (.+?) without an output path","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/api/serve_other.go","lineNumber":800,"sourceCode":"\t}\n\n\t// Validate the CORS origins\n\tfor _, origin := range serveOptions.CORS.Origin {\n\t\tif star := strings.IndexByte(origin, '*'); star >= 0 && strings.ContainsRune(origin[star+1:], '*') {\n\t\t\treturn ServeResult{}, fmt.Errorf(\"Invalid origin: %s\", origin)\n\t\t}\n\t}\n\n\t// Stuff related to the output directory only matters if there are entry points\n\toutdirPathPrefix := \"\"\n\tif len(ctx.args.entryPoints) > 0 {\n\t\t// Don't allow serving when builds are written to stdout\n\t\tif ctx.args.options.WriteToStdout {\n\t\t\twhat := \"entry points\"\n\t\t\tif len(ctx.args.entryPoints) == 1 {\n\t\t\t\twhat = \"an entry point\"\n\t\t\t}\n\t\t\treturn ServeResult{}, fmt.Errorf(\"Cannot serve %s without an output path\", what)\n\t\t}\n\n\t\t// Compute the output path prefix\n\t\tif serveOptions.Servedir != \"\" && ctx.args.options.AbsOutputDir != \"\" {\n\t\t\t// Make sure the output directory is contained in the \"servedir\" directory\n\t\t\trelPath, ok := ctx.realFS.Rel(serveOptions.Servedir, ctx.args.options.AbsOutputDir)\n\t\t\tif !ok {\n\t\t\t\treturn ServeResult{}, fmt.Errorf(\n\t\t\t\t\t\"Cannot compute relative path from %q to %q\\n\", serveOptions.Servedir, ctx.args.options.AbsOutputDir)\n\t\t\t}\n\t\t\trelPath = strings.ReplaceAll(relPath, \"\\\\\", \"/\") // Fix paths on Windows\n\t\t\tif relPath == \"..\" || strings.HasPrefix(relPath, \"../\") {\n\t\t\t\treturn ServeResult{}, fmt.Errorf(\n\t\t\t\t\t\"Output directory %q must be contained in serve directory %q\",\n\t\t\t\t\tprettyPrintPath(ctx.realFS, ctx.args.options.AbsOutputDir),\n\t\t\t\t\tprettyPrintPath(ctx.realFS, serveOptions.Servedir),\n\t\t\t\t)\n\t\t\t}","sourceCodeStart":782,"sourceCodeEnd":818,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/serve_other.go#L782-L818","documentation":"When using serve mode with entry points, esbuild needs a real output directory to write build artifacts that the server can serve. This error fires when the build is configured to write to stdout (WriteToStdout is true) instead of an output directory. The message distinguishes between 'an entry point' (singular) and 'entry points' (plural).","triggerScenarios":"Starting serve mode with one or more entry points while the build writes output to stdout (e.g. using --outfile=/dev/stdout, stdout targeting, or write:false without a proper outdir).","commonSituations":"Combining serve mode with a build config designed for piping output (e.g. esbuild --bundle --serve without --outdir), or reusing a programmatic build config that had stdout output.","solutions":["Set an output directory (outdir) in the build options when using serve mode with entry points","Remove any stdout-redirecting options such as write:false or stdout-format output","Do not use entry points with serve mode if you only need to serve static files (use servedir alone)"],"exampleFix":"// before\nesbuild.build({ entryPoints: ['app.ts'], write: false })\nesbuild.serve({ servedir: 'public' })\n// after\nesbuild.build({ entryPoints: ['app.ts'], outdir: 'public/dist' })\nesbuild.serve({ servedir: 'public' })","handlingStrategy":"validation","validationCode":"function validateServeConfig(buildOptions) {\n  if (buildOptions.entryPoints?.length > 0) {\n    if (!buildOptions.outdir) {\n      throw new Error('outdir is required when using serve mode with entry points')\n    }\n    if (buildOptions.write === false) {\n      throw new Error('write:false is not compatible with serve mode and entry points')\n    }\n  }\n}\nvalidateServeConfig(buildOptions)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set outdir when using serve mode with entry points","Do not use write:false or stdout output options with serve mode","Validate your build config for stdout-targeting options before starting serve"],"tags":["esbuild","serve","output","config"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}