Import Cycle Not Allowed

import cycle not allowed: package A imports package B which imports package A

Quick Answer

Two packages depend on each other creating a circular dependency. Break the cycle by extracting shared types into a third package.

Why This Happens

Go does not allow circular imports between packages. If package A imports package B and package B imports package A, the compiler rejects it. This forces clean dependency hierarchies. Break the cycle by moving shared types or interfaces into a separate package.

The Problem

// package user
import "myapp/order" // user imports order

// package order
import "myapp/user" // order imports user — cycle!

The Fix

// package types (new shared package)
type UserID int
type OrderID int

// package user
import "myapp/types" // no cycle

// package order
import "myapp/types" // no cycle

Step-by-Step Fix

  1. 1

    Identify the cycle

    Read the error to find the chain of imports that forms the cycle.

  2. 2

    Find shared types

    Identify which types or interfaces are used by both packages and cause the dependency.

  3. 3

    Extract to a common package

    Move shared types to a new package that both original packages can import without creating a cycle.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free