import cycle not allowed Go Origin: Application & API Last updated 4 Nov 2026

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.

Exact message you may see import cycle not allowedpackage imports imports : import cycle not allowedimport cycle not allowed in testimports app/utils imports app/models imports app/utils
Seen on: Go

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

  1. Move shared types to a separate lower-level package
  2. Depend on interfaces, not concrete packages
  3. Use go list -deps to inspect the graph

Detailed fix by platform

Go

  1. go list -f '{{.ImportPath}}: {{.Imports}}' ./... lists imports per package

How to diagnose

  1. Cycle — Which packages?
  2. Shared — Types to extract?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

assignment mismatch: 1 variable but f returns 2 values — Go: assignment mismatch: 1 variable but os.Open returns 2 values (Go)assignment mismatch: …cannot assign to struct field m[k].f in map — Go: cannot assign to struct field users["bob"].Age in map (Go)cannot assign to stru…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) (Go)cannot find package i…cannot refer to unexported name — Go: cannot refer to unexported name pkg.helper (undefined: pkg.helper) (Go)cannot refer to unexp…cannot use x as type in assignment/argument — Go: cannot use "5" (untyped string constant) as int value in argument to f (Go)cannot use x as type …does not implement interface (missing method) — Go: cannot use &Dog{} (value of type *Dog) as Animal value: *Dog does not implement Animal (missing method Speak) (Go)does not implement in…invalid operation: mismatched types — Go: invalid operation: a + b (mismatched types int and float64) (Go)invalid operation: mi…no required module provides package — Go: no required module provides package github.com/foo/bar; to add it: go get github.com/foo/bar (Go)no required module pr…import cy…

Explore the map of this error Full error map →

🧠 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.