Go "relative import paths are not supported in module mode" - Fix in CI
In module mode Go forbids relative import paths like ./utils or ../shared. Imports must use the full module-qualified path so Go can resolve them through the module graph, not the filesystem.
What this error means
A build fails with relative import paths are not supported in module mode or local import "./x" in non-local package. It typically appears when porting GOPATH-era code (which allowed relative imports) into a module.
./main.go:4:2: relative import paths are not supported in module mode
imported as "./internal/store"; use "github.com/org/app/internal/store"Common causes
Relative imports carried over from GOPATH code
Pre-module Go tolerated ./ and ../ imports. In module mode every import must be a full module-qualified path.
A script-style program importing a sibling directory
Importing ../shared to reach a neighboring directory is not how modules resolve packages - that target must be a package under a known module path.
How to fix it
Use full module-qualified import paths
Replace every relative import with the package’s canonical path under the module.
// instead of: import "./internal/store"
import "github.com/org/app/internal/store"Find and rewrite the relative imports
grep -rn '"\.\./\|"\./' --include='*.go' .
goimports -w .
go build ./...How to prevent it
- Always import packages by their full module path.
- Run
go build ./...andgoimportsto catch stray relative imports. - Avoid copying GOPATH-era code without converting its imports.