Go: package app/models imports app/utils imports app/models: import cycle not allowed
Two or more packages import each other directly or indirectly, which Go forbids.
import cycle not allowedpackage imports imports : import cycle not allowedimport cycle not allowed in testimports app/utils imports app/models imports app/utils Meaning
Break the cycle by moving shared types/interfaces to a third package, defining interfaces where they are used (consumer side), or merging packages. Dependency flow should be one-directional (e.g. handlers → services → models).
Common causes
- models and utils importing each other
- Shared types placed in the wrong package
- Circular dependency introduced by a new helper
- Test package importing the package under test incorrectly
- Generated code importing parent
⚡ Quick fix
- Move shared types to a separate lower-level package
- Depend on interfaces, not concrete packages
- Use
go list -depsto inspect the graph
Detailed fix by platform
Go
go list -f '{{.ImportPath}}: {{.Imports}}' ./...lists imports per package
How to diagnose
- Cycle — Which packages?
- Shared — Types to extract?
- Direction — One-way?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- assignment mismatch: 1 variable but f returns 2 values Go: assignment mismatch: 1 variable but os.Open returns 2 values
- cannot assign to struct field m[k].f in map Go: cannot assign to struct field users["bob"].Age in map
- cannot find package in any of GOROOT / GOPATH Go: cannot find package "github.com/pkg/errors" in any of: /usr/local/go/src/github.com/pkg/errors (from $GOROOT) /go/src/github.com/pkg/errors (from $GOPATH)
Most viewed in Go
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 4 Nov 2026