golang/go · error
working directory %q is not in either GOROOT(%q) or GOPATH(%
Error message
working directory %q is not in either GOROOT(%q) or GOPATH(%q)
What it means
Returned by the package-path resolver in go_ios_exec (go_ios_exec.go:295) when the current working directory is not nested under either runtime.GOROOT() or build.Default.GOPATH. The wrapper needs to derive the package's import path (subdir relative to GOROOT/GOPATH) to build and install the test app correctly.
Source
Thrown at misc/ios/go_ios_exec.go:295
return "", false, err
}
return subdir, true, nil
}
for _, p := range filepath.SplitList(build.Default.GOPATH) {
pabs, err := filepath.EvalSymlinks(p)
if err != nil {
return "", false, err
}
if !strings.HasPrefix(cwd, pabs) {
continue
}
subdir, err := filepath.Rel(pabs, cwd)
if err == nil {
return subdir, false, nil
}
}
return "", false, fmt.Errorf(
"working directory %q is not in either GOROOT(%q) or GOPATH(%q)",
cwd,
runtime.GOROOT(),
build.Default.GOPATH,
)
}
func infoPlist(pkgpath string) string {
return `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleName</key><string>golang.gotest</string>
<key>CFBundleSupportedPlatforms</key><array><string>iPhoneOS</string></array>
<key>CFBundleExecutable</key><string>gotest</string>
<key>CFBundleVersion</key><string>1.0</string>
<key>CFBundleShortVersionString</key><string>1.0</string>
<key>CFBundleIdentifier</key><string>` + bundleID + `</string>View on GitHub (pinned to b6b368adc5)
Solutions
- Run from within the package directory of a module-aware project; ensure go_ios_exec supports module mode (newer versions derive the path from `go list`).
- If relying on GOPATH mode, place the project under $GOPATH/src/<importpath> and run from there.
- Resolve symlinks so cwd evaluates under GOROOT/GOPATH.
- Upgrade go_ios_exec / the Go toolchain to a version that resolves package paths via `go list` rather than GOROOT/GOPATH prefixing.
Defensive patterns
Strategy: validation
Validate before calling
func cwdUnderGorootOrGopath() error {
cwd, _ := os.Getwd()
gr := runtime.GOROOT()
gp := build.Default.GOPATH
for _, p := range []string{gr, gp} {
if p == "" {
continue
}
pa, err := filepath.EvalSymlinks(p)
if err == nil && strings.HasPrefix(cwd, pa) {
return nil
}
}
return fmt.Errorf("cwd %q not under GOROOT/GOPATH", cwd)
} Prevention
- Run go_ios_exec from inside a module package directory.
- Upgrade to a Go version whose go_ios_exec resolves paths via `go list`.
- For GOPATH-mode projects, place code under $GOPATH/src/<importpath>.
When it happens
Trigger: Running go_ios_exec (i.e., `go test` with GOOS=ios) from a directory that is neither inside GOROOT/src nor inside any GOPATH workspace, in module-aware mode where the package path cannot be derived from the filesystem location.
Common situations: Module-mode project outside GOPATH (the most common modern setup) where the resolver's GOROOT/GOPATH heuristic does not apply; symlinks causing prefix checks to fail after EvalSymlinks; running from /tmp or a directory unrelated to the Go source tree.
Related errors
- xcrun simctl install booted %q: %v
- xcrun simctl launch booted %q: %v
- failed to locate cmd/go for target platform
- failed to locate cmd/compile for target platform
- GOROOT not found
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/d31c9871662bc014.
Report an issue: GitHub.