Skip to content
Latchkey

Go "go.mod file not found in current directory" - Fix in CI

A go command ran in a directory that has no go.mod in it or in any parent. Without a module root in scope, Go refuses before doing any work.

What this error means

A command stops immediately with go.mod file not found in current directory or any parent directory. In CI this almost always means the job ran from the wrong working directory, or before checkout placed the module files.

go
go: go.mod file not found in current directory or any parent directory;
	see 'go help modules'

Common causes

Command run from the wrong directory

CI executed go build from above the module root, or from an unrelated subdirectory, so no go.mod is in scope up the tree.

Module in a monorepo subfolder

The go.mod lives in a subdirectory but the job ran from the repo root, where there is no module file.

Checkout had not completed

A go command ran before actions/checkout placed the repository, so the working directory was empty.

How to fix it

Run from the module root

  1. Change into the directory that contains go.mod before any go command.
  2. For a monorepo, set working-directory on the run step.
.github/workflows/ci.yml
- run: go build ./...
  working-directory: service

Confirm checkout ran first

  1. Place actions/checkout before any setup-go or go step.
  2. List the directory to confirm go.mod is present.
.github/workflows/ci.yml
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
- run: ls go.mod && go build ./...

How to prevent it

  • Set working-directory explicitly for modules that live in subfolders.
  • Always run actions/checkout before any go command.
  • Add a ls go.mod smoke check at the top of the job.

Frequently asked questions

What causes ""go.mod file not found""?
CI executed go build from above the module root, or from an unrelated subdirectory, so no go.mod is in scope up the tree.
How do I fix "go.mod file not found"?
Run from the module root

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card