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: cannot load module listed in go.work file:
directory ../payments: stat ../payments: no such file or directoryCommon 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.
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.
- uses: actions/checkout@v4
with:
repository: org/payments
path: paymentsKeep go.work out of version control
echo 'go.work' >> .gitignore
echo 'go.work.sum' >> .gitignoreHow to prevent it
- Gitignore
go.work/go.work.sumunless CI truly builds the whole workspace. - Set
GOWORK=offin single-module CI jobs. - If you commit go.work, check out every module it
uses.