Skip to content
Latchkey

Go Workspace Errors - Fix go.work Problems in CI

A go.work file stitches several local modules into one workspace. In CI, where only part of the tree may be checked out, a workspace use directive can point at a module that is not present, breaking the build.

What this error means

A build fails because go.work references a directory that does not exist on the runner, or GOWORK is set to a path Go cannot find. It often works locally where every workspace module is cloned, but not in CI.

go output
go: cannot load module listed in go.work file:
	directory ../payments: stat ../payments: no such file or directory

Common causes

A committed go.work referencing missing modules

A go.work meant for local multi-module development was committed, but CI checks out only one module, so its use ../other directives point at absent directories.

GOWORK pointing at the wrong file

A GOWORK env var set to a path that does not exist (or off when a workspace is expected) makes Go fail to load the workspace.

How to fix it

Disable the workspace in CI

When CI builds a single module, turn the workspace off so go.work is ignored.

Terminal
export GOWORK=off
go build ./...

Check out every workspace module

If the workspace build is intentional, clone each module the go.work uses into the expected path.

.github/workflows/ci.yml
- uses: actions/checkout@v4
  with:
    repository: org/payments
    path: payments

Keep go.work out of version control

Terminal
echo 'go.work' >> .gitignore
echo 'go.work.sum' >> .gitignore

How to prevent it

  • Gitignore go.work/go.work.sum unless CI truly builds the whole workspace.
  • Set GOWORK=off in single-module CI jobs.
  • If you commit go.work, check out every module it uses.

Related guides

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