typescript-circular-dependency

Detect circular dependencies in TypeScript/JavaScript projects using madge.

1|Updated Jan 19, 2026
One-click install
npx skills add https://github.com/chipoto69/claude-skills --skill typescript-circular-dependency
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-circular-dependency
Source: https://github.com/chipoto69/claude-skills/tree/main/claudeception/examples/typescript-circular-dependency
Command: npx skills add https://github.com/chipoto69/claude-skills --skill typescript-circular-dependency

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Circular dependencies cause runtime initialization issues in TypeScript/JavaScript projects when modules import each other in a cycle. Even if compile succeeds, one import may evaluate to undefined or throw a runtime error due to incomplete initialization.

Core Features & Use Cases

  • Static analysis to detect circular dependencies across TS/JS modules.
  • Dependency graph visualization to reveal cycle paths.
  • Practical resolution guidance: extract shared interfaces, apply dependency injection, or refactor barrel patterns.
  • Use cases include large codebases with interdependent services, monorepos, or libraries with circular imports.

Quick Start

Install madge and run: npm install -D madge npx madge --circular --extensions ts,tsx src/

Frequently Asked Questions about typescript-circular-dependency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does a TypeScript import evaluate to undefined at runtime even when compilation succeeds?

Circular dependencies in TypeScript or JavaScript cause runtime initialization issues where incomplete module evaluation makes an import evaluate to undefined, often throwing an error despite successful compilation.

How do I detect circular dependencies in a TypeScript codebase?

Run static analysis using madge with the command `npx madge --circular --extensions ts,tsx src/` to detect circular dependencies and visualize the dependency graph revealing specific cycle paths across modules.

What is the best way to resolve circular imports in a JavaScript monorepo?

The best way to resolve circular imports is by extracting shared interfaces, applying dependency injection, or refactoring barrel patterns to break mutual module cycles and ensure stable runtime initialization.

Does madge work for analyzing circular dependencies in large interdependent service codebases?

Yes, madge runs static analysis to detect circular dependencies in large TypeScript and JavaScript codebases, including monorepos and libraries with interdependent services where mutual imports cause initialization order issues.

When should I use dynamic imports to fix a circular dependency?

Use dynamic imports as a resolution strategy when static analysis identifies mutual module cycles, allowing you to break the circular dependency pattern and prevent incomplete initialization errors at runtime.