Go "cannot load X: malformed module path" - Fix in CI
Module paths follow strict rules - a host, valid path elements, no leading dots, no uppercase escapes out of place. A path that breaks those rules is rejected as malformed before any download.
What this error means
A build fails with cannot load X: malformed module path "X": <reason>. Common reasons are a missing dot in the first element, an invalid character, or a trailing slash. It usually traces to a typo in go.mod or an import.
go: cannot load github.com//foo/bar: malformed module path "github.com//foo/bar": invalid path element ""Common causes
Typo in the module or import path
A double slash, trailing slash, or invalid character makes the path fail validation.
Missing dot in the first element
A non-stdlib path whose first element has no dot is not a valid module path.
How to fix it
Correct the path syntax
- Fix the malformed path in go.mod or the offending import to a valid module path.
- Run go mod tidy to re-resolve.
go mod tidy
go build ./...Verify against the real module path
- Confirm the path matches the module declaration on its host, character for character.
go list -m github.com/foo/barHow to prevent it
- Copy module paths exactly from the upstream go.mod.
- Avoid double or trailing slashes in import paths.
- Run
go mod tidyafter editing go.mod by hand.