stnd.buildSTANDARD MANUAL2026-07-15

5.2 Circular Dependency Detected

Circular Dependency Detected

Error: Circular dependency detected in module graph.

The Problem

You have a loop in your module dependencies. For example:

  • Module A depends on Module B
  • Module B depends on Module A

Or a larger cycle: A -> B -> C -> A.

The Why

Modules must load in a specific order (Dependencies first -> Dependents last). A cycle makes this impossible: A cannot load until B is ready, but B cannot load until A is ready. This is a fundamental logic error in your architecture.

The Solution

  1. Visualize the Graph: Map out your dependencies to find the cycle.
  2. Refactor:
    • Extract Shared Logic: Move the shared functionality that both modules need into a third, lower-level module (e.g., modules/common or modules/core).
    • Remove the Dependency: Does Module A really need to depend on Module B? Can they be independent?
    • Loose Coupling: Use hook injection or event listeners instead of hard dependencies if possible.