Skip to content
Latchkey

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.

go
./main.go:6:2: local import "./internal/util" in non-local package

Common 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

  1. Replace ./ and ../ imports with the module-qualified path from go.mod.
Go
import "github.com/yourorg/app/internal/util"

Rewrite imports in bulk

  1. Find relative imports and rewrite them to the canonical module path.
  2. Run go build to confirm they resolve.
Terminal
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.

Frequently asked questions

What causes ""relative import not supported""?
Code migrated from GOPATH still imports sibling packages with ./ or ../ paths.
How do I fix "relative import not supported"?
Use full module paths

Related guides

References

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