go-delve/delve · error
could not determine path for module %s (got %q and %q)
Error message
could not determine path for module %s (got %q and %q)
What it means
While building the module substitute-path map, 'go list' output assigned two different directories to the same module path after trimming the expected number of path elements, so the mapping is ambiguous and MakeGuessSusbtitutePathIn aborts with this error. Indicates module metadata that does not match the on-disk layout.
Source
Thrown at service/rpc2/client.go:669
if e.Module == nil {
continue
}
if !strings.HasPrefix(e.ImportPath, e.Module.Path) {
continue
}
pkgWithoutModule := e.ImportPath[len(e.Module.Path):]
elems := 0
for _, c := range pkgWithoutModule {
if c == '/' {
elems++
}
}
dir := e.Dir
for i := 0; i < elems; i++ {
dir = filepath.Dir(dir)
}
if mod2dir[e.Module.Path] != "" && mod2dir[e.Module.Path] != dir {
return nil, fmt.Errorf("could not determine path for module %s (got %q and %q)", e.Module.Path, mod2dir[e.Module.Path], dir)
}
mod2dir[e.Module.Path] = dir
if e.Name == "main" {
if importPathOfMainPackage != "" && importPathOfMainPackage != e.ImportPath {
importPathOfMainPackageOk = false
}
importPathOfMainPackage = e.ImportPath
}
}
buf, err = exec.Command("go", "env", "GOROOT").Output()
if err != nil {
return nil, err
}
clientGoroot := strings.TrimSpace(string(buf))
if !importPathOfMainPackageOk {
// There were multiple main packages
importPathOfMainPackage = ""
}View on GitHub (pinned to a23773e6c3)
Solutions
- Clean the module cache: go clean -modcache, then rebuild
- Remove or fix conflicting replace directives in go.mod
- Ensure the program is built with the same module layout you debug against
- Fall back to configuring substitutePath manually in your client instead of guessing
Example fix
// before sub, err := client.MakeGuessSusbtitutePathIn() // ambiguous module path // after // fix go.mod replace directives, then: sub, err := client.MakeGuessSusbtitutePathIn() // or set client.SubstitutePath manually
Defensive patterns
Strategy: fallback
Validate before calling
// inspect module list for duplicates before trusting the mapping
cmd := exec.Command("go", "list", "-m", "all")
out, err := cmd.Output()
hasDup := func(mod string) bool { return strings.Count(string(out), mod) > 1 } Try / catch
sub, err := client.MakeGuessSusbtitutePathIn()
if err != nil && strings.Contains(err.Error(), "could not determine path for module") {
// use explicit client.SubstitutePath entries instead of guessed ones
} Prevention
- Avoid conflicting replace directives pointing at multiple copies of one module
- Run go clean -modcache when module layout seems stale
- Keep vendor/ and module cache usage consistent
- Pin substitutePath in your IDE config instead of relying on guessing
When it happens
Trigger: GuessSubstitutePathIn RPC where a module appears multiple times in 'go list --json all' output with conflicting computed Dir values (after filepath.Dir applied elems times).
Common situations: Vendor directories mixed with module cache copies; replace directives pointing at local forks; monorepo layouts where module depth (elems) doesn't match directory structure; stale module cache.
Related errors
- error running go list %v: output %q
- too many arguments to "config substitutePath"
- could not find rule for %q
- could not find rule for %q
- Process %d has exited with status %d
AI-assisted analysis of go-delve/delve@a23773e6c3 (2026-08-31).
Data as JSON: /api/errors/c57f35ff2dfa5ccf.
Report an issue: GitHub.