golang/go · error · module.VersionError
parsing go.mod: missing module line
Error message
parsing go.mod: missing module line
What it means
When the go command fetches and summarizes a module's go.mod, it expects a `module` declaration giving the module path. If that line is missing (summary.module.Path == "") and the module is NOT a local filesystem replacement (which are exempt), it returns this error wrapped in module.VersionError.
Source
Thrown at src/cmd/go/internal/modload/modfile.go:626
suggestion := fmt.Sprintf(" for go.mod file; to add it:\n\tgo mod download %s", m.Path)
return nil, module.VersionError(actual, &sumMissingError{suggestion: suggestion})
}
}
summary, err := rawGoModSummary(ld, actual)
if err != nil {
return nil, err
}
if actual.Version == "" {
// The actual module is a filesystem-local replacement, for which we have
// unfortunately not enforced any sort of invariants about module lines or
// 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() {View on GitHub (pinned to b6b368adc5)
Solutions
- Report the issue to the module maintainer to add a module line.
- Select a different (correct) version of the module.
- Replace the broken module with a fixed fork via a `replace` directive.
Example fix
// before // upstream go.mod (broken): no `module` line $ go get example.com/lib@v1.0.0 // parsing go.mod: missing module line // after // replace example.com/lib v1.0.0 => github.com/you/lib-fork v1.0.1
Defensive patterns
Strategy: fallback
Validate before calling
// Before depending on a module, fetch its go.mod summary and check for a module line.
func hasModuleLine(modPath, version string) error {
return exec.Command("go", "mod", "download", "-json", modPath+"@"+version).Run()
} Type guard
null
Try / catch
null
Prevention
- Pin to known-good versions of third-party modules.
- Use `replace` to redirect to a corrected fork when upstream is broken.
- Verify modules with the checksum DB to detect corrupt content.
When it happens
Trigger: A version of a module whose published go.mod lacks a `module` line, fetched from a proxy or VCS (actual.Version != "").
Common situations: Hand-edited or corrupt go.mod published by a dependency; ancient pre-modules code; proxy serving truncated content.
Related errors
- ${GoModToolVersion} is required for tool directives in go.mo
- updates to go.mod needed, but go.mod is part of the overlay
- can't resolve module using the vendor directory (Use -mod=m
- not a known dependency
- cannot find package
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/490565b964c17ac2.
Report an issue: GitHub.