typescript-circular-dependency

Detect circular dependencies in TypeScript/JavaScript projects using Madge and recommend refactoring strategies.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Circular dependencies between modules can cause runtime initialization issues in TypeScript/JavaScript projects, where imports resolve to undefined despite successful compilation.

Core Features & Use Cases

  • Detect cycles using tools like Madge to visualize dependency graphs
  • Identify common circular patterns (service-to-service, type-import loops, and index barrel cycles)
  • Provide practical resolution strategies (extract shared interfaces, introduce dependency injection, use dynamic or type-only imports, and adjust barrels)

Quick Start

Run madge to identify circular dependencies in your project and apply a chosen refactor to break the cycle.

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 dependencies in TypeScript when imports resolve to undefined?

Circular dependencies in TypeScript cause runtime initialization errors where imports resolve to undefined. You can resolve these cycles by extracting shared interfaces, introducing dependency injection, or using dynamic and type-only imports to break the module loop.

What is the best way to detect circular module dependencies in a JavaScript project?

Detecting circular module dependencies in JavaScript projects is best done using Madge to visualize the dependency graph. This identifies direct and indirect module cycles that cause flaky behavior in Node.js or frontend builds.

How do I resolve barrel index file cycles causing flaky behavior in Node.js builds?

Resolving barrel index file cycles requires adjusting your barrel exports to prevent circular references. You can break these index cycles by extracting shared interfaces or using type-only imports to stabilize flaky Node.js builds.

Why does TypeScript compile successfully but throw runtime undefined errors with service-to-service imports?

TypeScript compilation succeeds but runtime undefined errors occur because service-to-service circular dependencies cause incomplete module initialization. Extracting shared interfaces or introducing dependency injection breaks these service cycles.

Can I use type-only imports to break circular dependencies in frontend builds?

Yes, you can use type-only imports to break circular dependencies in frontend builds. This approach prevents runtime initialization loops by ensuring modules only import type definitions rather than executable code.

What are common circular dependency patterns in TypeScript projects?

Common circular dependency patterns in TypeScript projects include service-to-service imports, type-import loops, and barrel index cycles. Identifying these specific patterns allows targeted refactoring like extracting shared interfaces or adjusting barrels.