{"record":{"id":"0ba51709a6ce8617","repo":"evanw/esbuild","slug":"invalid-serve-path-s","errorCode":null,"errorMessage":"Invalid serve path: %s","messagePattern":"Invalid serve path: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/api/serve_other.go","lineNumber":771,"sourceCode":"\t\treturn ServeResult{}, errors.New(\"Cannot serve a disposed context\")\n\t}\n\n\t// Don't allow starting serve mode multiple times\n\tif ctx.handler != nil {\n\t\treturn ServeResult{}, errors.New(\"Serve mode has already been enabled\")\n\t}\n\n\t// Don't allow starting serve mode multiple times\n\tif (serveOptions.Keyfile != \"\") != (serveOptions.Certfile != \"\") {\n\t\treturn ServeResult{}, errors.New(\"Must specify both key and certificate for HTTPS\")\n\t}\n\n\t// Validate the \"servedir\" path\n\tif serveOptions.Servedir != \"\" {\n\t\tif absPath, ok := ctx.realFS.Abs(serveOptions.Servedir); ok {\n\t\t\tserveOptions.Servedir = absPath\n\t\t} else {\n\t\t\treturn ServeResult{}, fmt.Errorf(\"Invalid serve path: %s\", serveOptions.Servedir)\n\t\t}\n\t}\n\n\t// Validate the \"fallback\" path\n\tif serveOptions.Fallback != \"\" {\n\t\tif absPath, ok := ctx.realFS.Abs(serveOptions.Fallback); ok {\n\t\t\tserveOptions.Fallback = absPath\n\t\t} else {\n\t\t\treturn ServeResult{}, fmt.Errorf(\"Invalid fallback path: %s\", serveOptions.Fallback)\n\t\t}\n\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}","sourceCodeStart":753,"sourceCodeEnd":789,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/serve_other.go#L753-L789","documentation":"The servedir option for serve mode must be resolvable to an absolute path by the filesystem provider. This error fires when ctx.realFS.Abs(serveOptions.Servedir) fails, indicating the path is invalid or unresolvable from the current working directory.","triggerScenarios":"Passing a servedir that does not exist, has invalid characters, or is on an inaccessible volume, causing Abs() to fail.","commonSituations":"Pointing servedir to a deleted or typo'd directory name, a path with permission issues, or a relative path that cannot be resolved because the process working directory is gone.","solutions":["Verify the servedir path exists and is accessible before starting serve mode","Use an absolute path resolved via path.resolve() or filepath.Abs()","Check directory read permissions if the path should exist"],"exampleFix":"// before\nesbuild.serve({ servedir: './nonexistent-dir' })\n// after\nimport fs from 'fs'\nif (!fs.existsSync('./public')) throw new Error('servedir missing')\nesbuild.serve({ servedir: path.resolve('./public') })","handlingStrategy":"validation","validationCode":"import fs from 'fs'\nimport path from 'path'\nfunction validateServedir(servedir) {\n  const abs = path.resolve(servedir)\n  if (!fs.existsSync(abs) || !fs.statSync(abs).isDirectory()) {\n    throw new Error(`servedir does not exist or is not a directory: ${abs}`)\n  }\n  return abs\n}\nserveOptions.servedir = validateServedir(serveOptions.servedir)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check that servedir exists and is a readable directory before starting serve mode","Resolve servedir to an absolute path before passing it","Verify filesystem permissions on the servedir path"],"tags":["esbuild","serve","filesystem","path"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}