Go "cannot determine module path" - Fix go mod init in CI
go mod init was run without a module path and Go could not infer one. With no import comment, no recognizable VCS remote, and no GOPATH hint, Go has nothing to name the module and refuses.
What this error means
A go mod init step fails with cannot determine module path for source directory ... and a hint to pass the path explicitly. It commonly happens in CI where the repo is checked out without a usable VCS remote to infer from.
go: cannot determine module path for source directory
/home/runner/work/app (outside GOPATH, module path must be specified)
Example usage:
'go mod init example.com/m' to initialize a v0 or v1 moduleCommon causes
go mod init run with no module path
Without an explicit argument, Go tries to infer the module path from the VCS remote or GOPATH. When it cannot, it errors.
No inferable VCS remote in the checkout
A shallow or detached CI checkout may lack the remote URL Go would otherwise use to derive the path.
How to fix it
Pass the module path explicitly
Always give go mod init the full canonical module path so nothing has to be inferred.
go mod init github.com/yourorg/yourrepo
go mod tidyCommit go.mod instead of initializing in CI
- Generate go.mod once locally with the correct path and commit it.
- Let CI build against the committed go.mod rather than running
go mod init. - Reserve
go mod initfor the one-time project setup.
How to prevent it
- Commit a go.mod with the canonical module path; do not init in CI.
- Always pass the module path argument to
go mod init. - Use a host-qualified path (e.g.
github.com/org/repo).