typescript-circular-dependency

Identifies circular dependencies in TS/JS projects and recommends structural fixes.

Updated Oct 27, 2025
One-click install
npx skills add https://github.com/SomtoUgeh/dotfiles --skill typescript-circular-dependency-somtougeh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-circular-dependency
Source: https://github.com/SomtoUgeh/dotfiles/tree/main/claude/skills/claudeception/examples/typescript-circular-dependency
Command: npx skills add https://github.com/SomtoUgeh/dotfiles --skill typescript-circular-dependency-somtougeh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Circular dependencies between modules often lead to runtime errors, undefined exports, and hard-to-debug behavior in TypeScript/JavaScript projects.

Core Features & Use Cases

  • Detect and visualize cycles across TS/TSX files using tooling like Madge to identify circular dependencies.
  • Recognize common patterns such as Service-to-Service dependencies, barrel/index.ts cycles, and type/import cycles, and provide actionable resolution guidance.
  • Resolution guidance includes extracting shared interfaces/types, applying dependency injection, using dynamic imports, or converting to type-only imports to break cycles.

Quick Start

Install and run the circular dependency detector. npm install -g madge madge --circular --extensions ts,tsx src/ Optionally generate a visual graph: madge --circular --image graph.svg src/

Frequently Asked Questions about typescript-circular-dependency

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

FAQPage Schema
How do I fix circular dependency errors causing undefined exports in TypeScript?

Resolve circular dependencies in TypeScript by breaking import cycles through extracting shared interfaces, applying dependency injection, leveraging dynamic imports, or converting to type-only imports to prevent undefined exports and initialization errors.

How do I detect circular dependencies in a JavaScript or TypeScript project?

Detect circular dependencies in a JavaScript or TypeScript project by installing and running Madge. Execute `madge --circular --extensions ts,tsx src/` to identify cyclic module imports, and optionally generate a visual graph with `--image graph.svg`.

Why does my barrel file or index.ts create a circular import cycle?

Barrel files or index.ts exports create circular import cycles when modules import from the barrel while simultaneously being re-exported by it. Break this pattern by importing modules directly or extracting shared types to a separate file.

What is the best way to resolve service-to-service circular dependencies in TS/TSX files?

The best way to resolve service-to-service circular dependencies in TS/TSX files is applying dependency injection or extracting shared interfaces. This decouples the interdependent modules and stops the initialization errors caused by the cyclic imports.

Can I use dynamic imports to break module resolution cycles in TS?

Yes, you can use dynamic imports to break module resolution cycles in TS. By loading the interdependent module asynchronously at runtime, you prevent the static initialization order from causing undefined export errors across your files.