{"record":{"id":"248a88498d73b8bb","repo":"evanw/esbuild","slug":"cannot-compute-relative-path-from-q-to-q","errorCode":null,"errorMessage":"Cannot compute relative path from %q to %q\n","messagePattern":"Cannot compute relative path from %q to %q\n","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/api/serve_other.go","lineNumber":808,"sourceCode":"\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}\n\t\t\tif relPath != \".\" {\n\t\t\t\toutdirPathPrefix = relPath\n\t\t\t}\n\t\t}\n\t}\n\n\t// Determine the host\n\tvar listener net.Listener","sourceCodeStart":790,"sourceCodeEnd":826,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/serve_other.go#L790-L826","documentation":"When both servedir and outdir are set in serve mode, esbuild computes a relative path from servedir to outdir using filepath.Rel(). This error fires when that computation fails, which can happen when the two paths are on different volumes (e.g. different drive letters on Windows).","triggerScenarios":"Setting servedir and outdir to paths on different filesystem volumes or drives, making a relative path between them impossible to compute.","commonSituations":"On Windows, placing servedir on C:\\ and outdir on D:\\, or on Linux/macOS using paths that span different mount points in a way filepath.Rel cannot bridge.","solutions":["Ensure servedir and outdir are on the same drive or volume","Place outdir inside or adjacent to servedir","Use an absolute outdir that shares a common prefix with servedir"],"exampleFix":"// before (Windows)\nesbuild.serve({ servedir: 'C:\\\\serve' }) // outdir: D:\\out\n// after\nesbuild.serve({ servedir: 'C:\\\\serve' }) // outdir: C:\\\\serve\\out","handlingStrategy":"validation","validationCode":"import path from 'path'\nfunction validateServeOutdir(servedir, outdir) {\n  const absServe = path.resolve(servedir)\n  const absOut = path.resolve(outdir)\n  // On Windows, check same drive letter\n  if (process.platform === 'win32') {\n    const serveDrive = absServe.substring(0, 2)\n    const outDrive = absOut.substring(0, 2)\n    if (serveDrive.toLowerCase() !== outDrive.toLowerCase()) {\n      throw new Error(`servedir (${absServe}) and outdir (${absOut}) must be on the same drive`)\n    }\n  }\n}\nvalidateServeOutdir(serveOptions.servedir, buildOptions.outdir)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep servedir and outdir on the same filesystem volume or drive","Place outdir inside or adjacent to servedir","On Windows, verify both paths share the same drive letter"],"tags":["esbuild","serve","filesystem","windows","path"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}