golang/go · error
invalid module path %q
Error message
invalid module path %q
What it means
newCodeRepo calls module.SplitPathVersion on the module path; if it returns ok==false the path cannot be decomposed into a prefix and version suffix, so the path is syntactically invalid. The %q is the offending path.
Source
Thrown at src/cmd/go/internal/modfetch/coderepo.go:72
// pseudoMajor is the major version prefix to require when generating
// pseudo-versions for this module, derived from the module path. pseudoMajor
// is empty if the module path does not include a version suffix (that is,
// accepts either v0 or v1).
pseudoMajor string
}
// newCodeRepo returns a Repo that reads the source code for the module with the
// given path, from the repo stored in code.
// codeRoot gives the import path corresponding to the root of the repository,
// and subdir gives the subdirectory within the repo containing the module.
// If subdir is empty, the module is at the root of the repo.
func newCodeRepo(code codehost.Repo, codeRoot, subdir, path string) (Repo, error) {
if !hasPathPrefix(path, codeRoot) {
return nil, fmt.Errorf("mismatched repo: found %s for %s", codeRoot, path)
}
pathPrefix, pathMajor, ok := module.SplitPathVersion(path)
if !ok {
return nil, fmt.Errorf("invalid module path %q", path)
}
if codeRoot == path {
pathPrefix = path
}
pseudoMajor := module.PathMajorPrefix(pathMajor)
// Compute codeDir = bar, the subdirectory within the repo
// corresponding to the module root.
//
// At this point we might have:
// path = github.com/rsc/foo/bar/v2
// codeRoot = github.com/rsc/foo
// pathPrefix = github.com/rsc/foo/bar
// pathMajor = /v2
// pseudoMajor = v2
//
// which gives
// codeDir = barView on GitHub (pinned to b6b368adc5)
Solutions
- Print go.mod and verify the module path follows the Go module path rules (lowercase, dot-separated, optional /vN suffix where N>=2).
- Correct the module path in the upstream go.mod and re-tag.
- Inspect the go-import meta tag and ensure the advertised path is well-formed.
- Use `go mod edit -module=<correct path>` to fix a local module declaration.
Example fix
// before module github.com/User/Repo // uppercase letters are invalid // error: invalid module path "github.com/User/Repo" // after module github.com/user/repo
Defensive patterns
Strategy: validation
Validate before calling
func modulePathValid(path string) bool {
_, _, ok := module.SplitPathVersion(path)
return ok
} Type guard
func isValidModulePath(p string) bool {
if p == "" { return false }
if !utf8.ValidString(p) { return false }
if strings.ContainsAny(p, "\\ABCDEFGHIJKLMNOPQRSTUVWXYZ") { return false }
_, _, ok := module.SplitPathVersion(p)
return ok
} Prevention
- Follow Go module path conventions: lowercase, dot-separated, optional /vN (N>=2) suffix.
- Lint go.mod files with `go mod verify` and module-path validators in CI.
- Never hand-edit the module directive — use `go mod edit -module=`.
When it happens
Trigger: module.SplitPathVersion fails — path contains invalid version characters, an unparseable /vN suffix, escapes, or control characters. Indicates a corrupt go.mod, replace directive, or vanity meta tag emitting a malformed path.
Common situations: A go.mod with a typo'd module path (e.g. trailing slash, uppercase letters, '/v' followed by non-digit); a vanity server emitting a path with disallowed characters; a replace directive pointing at a relative path leaking into module resolution.
Related errors
- %s has malformed module path %q%s at revision %s
- invalid %s path: %v
- invalid version interval: %q
- non-semver module version %q
- invalid version %q
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/dfaf4b550bdb321b.
Report an issue: GitHub.