Go "relative import paths not supported in module mode" - Fix in CI
In module mode Go does not allow relative import paths like ./util or ../shared. Imports must use the full module path so they resolve unambiguously.
What this error means
A build fails with local import "./util" in non-local package or relative import paths are not supported in module mode. It usually means GOPATH-era relative imports survived a module migration.
./main.go:6:2: local import "./internal/util" in non-local packageCommon causes
Leftover GOPATH-style relative imports
Code migrated from GOPATH still imports sibling packages with ./ or ../ paths.
Copy-pasted relative import
A relative import was introduced by hand and never rewritten to the full module path.
How to fix it
Use full module paths
- Replace ./ and ../ imports with the module-qualified path from go.mod.
import "github.com/yourorg/app/internal/util"Rewrite imports in bulk
- Find relative imports and rewrite them to the canonical module path.
- Run go build to confirm they resolve.
grep -rl '"\./' . | xargs sed -i 's#"\./internal#"github.com/yourorg/app/internal#g'
go build ./...How to prevent it
- Always import sibling packages by full module path.
- Audit for relative imports during a GOPATH-to-modules migration.
- Let goimports normalize import paths.