golang/go · error
parsing go.mod: module declares its path as: %s bu
Error message
parsing go.mod: module declares its path as: %s but was required as: %s
What it means
Returned while building a module graph summary (modfile.go:638) when the module directive inside a fetched dependency's go.mod declares a different path than the path it was required under, and also different from any replacement target. The toolchain refuses to use a module whose self-declared identity disagrees with how it was imported, because import resolution within that module would be ambiguous.
Source
Thrown at src/cmd/go/internal/modload/modfile.go:638
// matching module paths. Anything goes.
//
// TODO(bcmills): Remove this special-case, update tests, and add a
// release note.
} else {
if summary.module.Path == "" {
return nil, module.VersionError(actual, errors.New("parsing go.mod: missing module line"))
}
// In theory we should only allow mpath to be unequal to m.Path here if the
// version that we fetched lacks an explicit go.mod file: if the go.mod file
// is explicit, then it should match exactly (to ensure that imports of other
// packages within the module are interpreted correctly). Unfortunately, we
// can't determine that information from the module proxy protocol: we'll have
// to leave that validation for when we load actual packages from within the
// module.
if mpath := summary.module.Path; mpath != m.Path && mpath != actual.Path {
return nil, module.VersionError(actual,
fmt.Errorf("parsing go.mod:\n"+
"\tmodule declares its path as: %s\n"+
"\t but was required as: %s", mpath, m.Path))
}
}
for _, mainModule := range ld.MainModules.Versions() {
if index := ld.MainModules.Index(mainModule); index != nil && len(index.exclude) > 0 {
// Drop any requirements on excluded versions.
// Don't modify the cached summary though, since we might need the raw
// summary separately.
haveExcludedReqs := false
for _, r := range summary.require {
if index.exclude[r] {
haveExcludedReqs = true
break
}
}
if haveExcludedReqs {View on GitHub (pinned to b6b368adc5)
Solutions
- Update the require/replace to the path the module actually declares (the value shown as 'module declares its path as').
- If using a replace to a local directory, fix the module directive in that directory's go.mod to match the required path.
- Clear the corrupted entry from the module cache and re-download: 'go clean -modcache && go mod download'.
- Report to the module author if a published version genuinely ships the wrong module path.
Example fix
// before go.mod requires: require example.com/old v1.0.0 // fetched go.mod says: module example.com/new // error: parsing go.mod: module declares its path as: example.com/new // but was required as: example.com/old // after require example.com/new v1.0.0
Defensive patterns
Strategy: validation
Validate before calling
// When using a replace target, verify its go.mod module line matches the required path:
// repMod := exec.Command("go", "mod", "edit", "-print").run-in-replace-dir
// require repMod == requiredPath before committing the replace directive. Type guard
func modulePathMatchesRequired(f *modfile.File, required string) bool {
return f != nil && f.Module != nil && (f.Module.Mod.Path == required)
} Prevention
- After renaming a module, update every require and the module's own module directive in lockstep.
- For local replacements, keep the replaced directory's module line equal to the required path.
- Run 'go list -m all' in CI to surface path mismatches early.
When it happens
Trigger: A go.mod fetched for path A declares 'module B'; the requirement pointed at A but the downloaded artifact is actually B; a misconfigured module proxy or fork served the wrong go.mod; a replace directive targets a directory whose go.mod names a different module.
Common situations: A dependency was renamed/moved but an old require still references the former path; a fork served under the original path; a vendored or replaced local module whose go.mod module line was not updated after a rename.
Related errors
- parsing %s: %v
- %s/%s and ...%s/go.mod both have ...%s module paths at revis
- %s/%s is missing module path at revision %s
- %s/%s has non-...%s module path %q at revision %s
- %s is missing module path%s at revision %s
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/1c4cc084fb5c1119.
Report an issue: GitHub.