liveBook · Manning

Circular dependency

As explained in Acing the Frontend Interview

A circular dependency is a dependency relationship in which modules directly or indirectly import one another in a cycle.

A circular dependency occurs when modules directly or indirectly import one another. ES modules support these cycles, but initialization order can expose incomplete or undefined imported values. section 3.4

Initialization hazard

Module A imports Module B, while Module B imports Module A. The engine initializes each module up to its export statements before resolving imports; if either module reads an imported value before its dependency finishes initializing, that value may be incomplete or undefined. section 3.4

Interview-ready points:

  • Treat circular dependencies as a maintainability risk and avoid them whenever possible. section 3.4
  • Relate the issue to ES module initialization rather than assuming imports are immediately usable. section 3.4

How Acing the Frontend Interview covers it

How deep it goes
Explains initialization order and incomplete imports, but stops short of showing a refactoring procedure.
Examples
Uses mutually importing modules and an imported value accessed before dependency initialization completes.
What it assumes
Assumes familiarity with modules, imports, exports, and JavaScript initialization behavior.
What you can do after
Evaluate module cycles and explain why initialization can produce incomplete or undefined imported values.
How it connects
Connects circular dependencies with ES modules, CommonJS, imports, exports, and module initialization.

Also explained in

Compare how 7 books explain circular dependency →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Acing the Frontend Interview. The section links point to the parts of the book it draws on.