evanw/esbuild · error

The working directory

Error message

The working directory %q is not an absolute path

What it means

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.

Solutions

  1. Resolve the path to absolute before passing it, e.g. path.resolve('./src') in Node.js or filepath.Abs in Go
  2. Omit the AbsWorkingDir option entirely to let esbuild use os.Getwd() automatically

Example fix

// before
esbuild.build({ absWorkingDir: './dist', entryPoints: ['app.ts'] })
// after
import path from 'path'
esbuild.build({ absWorkingDir: path.resolve('./dist'), entryPoints: ['app.ts'] })
Defensive patterns

Strategy: validation

Validate before calling

import path from 'path'
const workDir = process.env.BUILD_DIR || './dist'
if (!path.isAbsolute(workDir)) {
  throw new Error(`absWorkingDir must be absolute, got: ${workDir}`)
}
// or simply:
esbuild.build({ absWorkingDir: path.resolve(workDir), ... })

Prevention

When it happens

Trigger: Calling esbuild.build({ absWorkingDir: './src' }) or the Go API with a relative path as the working directory option.

Common situations: Passing a relative path from a config file or CLI wrapper that was not resolved to absolute, or hardcoding a relative project path.

Related errors


AI-assisted analysis of evanw/esbuild@f6058f8364 (2026-08-09). Data as JSON: /api/errors/b3628cc815b6f7ff. Report an issue: GitHub.

Appendix: source

Thrown at internal/fs/fs_real.go:86

		fp.isWindows = true
		fp.pathSeparator = '\\'
	} else {
		fp.isWindows = false
		fp.pathSeparator = '/'
	}

	// Come up with a default working directory if one was not specified
	fp.cwd = options.AbsWorkingDir
	if fp.cwd == "" {
		if cwd, err := os.Getwd(); err == nil {
			fp.cwd = cwd
		} else if fp.isWindows {
			fp.cwd = "C:\\"
		} else {
			fp.cwd = "/"
		}
	} else if !fp.isAbs(fp.cwd) {
		return nil, fmt.Errorf("The working directory %q is not an absolute path", fp.cwd)
	}

	// Resolve symlinks in the current working directory. Symlinks are resolved
	// when input file paths are converted to absolute paths because we need to
	// recognize an input file as unique even if it has multiple symlinks
	// pointing to it. The build will generate relative paths from the current
	// working directory to the absolute input file paths for error messages,
	// so the current working directory should be processed the same way. Not
	// doing this causes test failures with esbuild when run from inside a
	// symlinked directory.
	//
	// This deliberately ignores errors due to e.g. infinite loops. If there is
	// an error, we will just use the original working directory and likely
	// encounter an error later anyway. And if we don't encounter an error
	// later, then the current working directory didn't even matter and the
	// error is unimportant.
	if path, err := fp.evalSymlinks(fp.cwd); err == nil {
		fp.cwd = path

View on GitHub (pinned to f6058f8364)