{"record":{"id":"b3628cc815b6f7ff","repo":"evanw/esbuild","slug":"the-working-directory-q-is-not-an-absolute-path","errorCode":null,"errorMessage":"The working directory %q is not an absolute path","messagePattern":"The working directory %q is not an absolute path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/fs/fs_real.go","lineNumber":86,"sourceCode":"\t\tfp.isWindows = true\n\t\tfp.pathSeparator = '\\\\'\n\t} else {\n\t\tfp.isWindows = false\n\t\tfp.pathSeparator = '/'\n\t}\n\n\t// Come up with a default working directory if one was not specified\n\tfp.cwd = options.AbsWorkingDir\n\tif fp.cwd == \"\" {\n\t\tif cwd, err := os.Getwd(); err == nil {\n\t\t\tfp.cwd = cwd\n\t\t} else if fp.isWindows {\n\t\t\tfp.cwd = \"C:\\\\\"\n\t\t} else {\n\t\t\tfp.cwd = \"/\"\n\t\t}\n\t} else if !fp.isAbs(fp.cwd) {\n\t\treturn nil, fmt.Errorf(\"The working directory %q is not an absolute path\", fp.cwd)\n\t}\n\n\t// Resolve symlinks in the current working directory. Symlinks are resolved\n\t// when input file paths are converted to absolute paths because we need to\n\t// recognize an input file as unique even if it has multiple symlinks\n\t// pointing to it. The build will generate relative paths from the current\n\t// working directory to the absolute input file paths for error messages,\n\t// so the current working directory should be processed the same way. Not\n\t// doing this causes test failures with esbuild when run from inside a\n\t// symlinked directory.\n\t//\n\t// This deliberately ignores errors due to e.g. infinite loops. If there is\n\t// an error, we will just use the original working directory and likely\n\t// encounter an error later anyway. And if we don't encounter an error\n\t// later, then the current working directory didn't even matter and the\n\t// error is unimportant.\n\tif path, err := fp.evalSymlinks(fp.cwd); err == nil {\n\t\tfp.cwd = path","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/internal/fs/fs_real.go#L68-L104","documentation":"esbuild's AbsWorkingDir build option must be an absolute filesystem path. The filesystem provider (fs_real.go) validates this during initialization and rejects relative paths. This is needed because esbuild resolves all input file paths relative to the working directory and must produce absolute paths for uniqueness.","triggerScenarios":"Calling esbuild.build({ absWorkingDir: './src' }) or the Go API with a relative path as the working directory option.","commonSituations":"Passing a relative path from a config file or CLI wrapper that was not resolved to absolute, or hardcoding a relative project path.","solutions":["Resolve the path to absolute before passing it, e.g. path.resolve('./src') in Node.js or filepath.Abs in Go","Omit the AbsWorkingDir option entirely to let esbuild use os.Getwd() automatically"],"exampleFix":"// before\nesbuild.build({ absWorkingDir: './dist', entryPoints: ['app.ts'] })\n// after\nimport path from 'path'\nesbuild.build({ absWorkingDir: path.resolve('./dist'), entryPoints: ['app.ts'] })","handlingStrategy":"validation","validationCode":"import path from 'path'\nconst workDir = process.env.BUILD_DIR || './dist'\nif (!path.isAbsolute(workDir)) {\n  throw new Error(`absWorkingDir must be absolute, got: ${workDir}`)\n}\n// or simply:\nesbuild.build({ absWorkingDir: path.resolve(workDir), ... })","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always wrap working directory paths in path.resolve() before passing to esbuild","Omit absWorkingDir entirely to let esbuild auto-detect via os.Getwd()","Validate paths from config files or environment variables before use"],"tags":["esbuild","filesystem","config","path"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}