nats-io/nats-server · error

nats: failed to get home dir, require %HOMEDRIVE% and %HOMEP

Error message

nats: failed to get home dir, require %HOMEDRIVE% and %HOMEPATH% or %USERPROFILE%

What it means

homeDir() on Windows: neither HOMEDRIVE+HOMEPATH nor USERPROFILE environment variables are set, so the user home directory — used to resolve relative config and pid paths — cannot be determined. The missing Windows environment variables are the input at fault.

Source

Thrown at server/opts.go:6598

// 1. Try to open a file with path "pidStr" (absolute or relative).
// 2. If such a file exists and can be read, return its contents.
// 3. Otherwise, return the original "pidStr" string.
func maybeReadPidFile(pidStr string) string {
	if b, err := os.ReadFile(pidStr); err == nil {
		return string(b)
	}
	return pidStr
}

func homeDir() (string, error) {
	if runtime.GOOS == "windows" {
		homeDrive, homePath := os.Getenv("HOMEDRIVE"), os.Getenv("HOMEPATH")
		userProfile := os.Getenv("USERPROFILE")

		home := filepath.Join(homeDrive, homePath)
		if homeDrive == _EMPTY_ || homePath == _EMPTY_ {
			if userProfile == _EMPTY_ {
				return _EMPTY_, errors.New("nats: failed to get home dir, require %HOMEDRIVE% and %HOMEPATH% or %USERPROFILE%")
			}
			home = userProfile
		}

		return home, nil
	}

	home := os.Getenv("HOME")
	if home == _EMPTY_ {
		return _EMPTY_, errors.New("failed to get home dir, require $HOME")
	}
	return home, nil
}

func expandPath(p string) (string, error) {
	p = os.ExpandEnv(p)

	if !strings.HasPrefix(p, "~") {

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Set HOMEDRIVE/HOMEPATH or USERPROFILE in the service environment
  2. Pass absolute paths for config and pid files so home resolution is unnecessary
  3. Run the server from a properly configured user profile
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at server/opts.go:6598 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/b8c1830ebe275f21. Report an issue: GitHub.