Skip to content
Latchkey

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 output
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 module

Common 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.

Terminal
go mod init github.com/yourorg/yourrepo
go mod tidy

Commit go.mod instead of initializing in CI

  1. Generate go.mod once locally with the correct path and commit it.
  2. Let CI build against the committed go.mod rather than running go mod init.
  3. Reserve go mod init for 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).

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →