circular dependency
Two or more pieces of code or data that depend on each other in a loop, so none can be built or resolved first.
In more detail
Circular dependencies make code hard to change, and tools that follow a chain of references must detect cycles or they would loop forever. Between modules, a cycle can mean one module sees another's exports before they are ready. Layered architectures avoid cycles by only allowing dependencies in one direction.
Example
The lesson's token resolver throws "Circular alias" after following more than five references.Related terms
- layered architecture — Organising a system into ranked layers where each layer may only use layers below it.
- token alias — A token whose value is a reference to another token, written in curly braces such as {semantic.action.bg}.
- dependency — Anything a program needs in order to work, such as a library, a tool or another service.
- directed acyclic graph — A directed graph with no cycles, so following edges can never bring you back to where you started.
- monorepo — A single version-control repository that holds several related projects, such as a web app, an API and their shared libraries.
- CommonJS — Node.js's original module system, which loads code with require() and exports it with module.exports.
- ECMAScript modules — The standard JavaScript module system, written with import and export statements, used by browsers and modern tools.
- type-only import — An import written import type { X } or import { type X }, which brings in only types and is always removed from the output.
- module — A file of code whose functions, classes and variables other files can use by importing it.
Taught in
- Design Systems Architecture: Foundations, Layers & Taxonomy — Design Systems & Component Engineering
- Design Tokens: W3C Specs, Global, Semantic & Component Tokens — Design Systems & Component Engineering
- Monorepo Architecture: Workspaces & Turborepo — Production Full-Stack Engineering
- Native Module Systems: ESM Loader Hooks vs CommonJS — Node.js Internals & Backend Services
- ECMAScript Modules, CJS Interop And verbatimModuleSyntax — Production TypeScript