typescript-circular-dependency

Detect and resolve circular dependencies in TypeScript and JavaScript projects.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Detects and resolves circular import dependencies in TypeScript and JavaScript projects, preventing runtime errors caused by partially initialized modules.

Core Features & Use Cases

  • Circular dependency detection in TS/JS project graphs.
  • Concrete resolution strategies: dependency extraction, DI, type-only imports, and barrel-file adjustments.
  • Use Case: When runtime errors like Cannot access 'X' before initialization or undefined imports appear, often due to import cycles.

Quick Start

Run a dependency graph analysis to locate cycles and apply fixes:

  • Install and use Madge to visualize cycles in your codebase.
  • Identify patterns such as service-to-service, type imports, or barrel files.
  • Implement fixes (e.g., extract shared interfaces, introduce DI, or restructure imports).
  • Re-run the analysis and tests to confirm cycles are resolved.

Frequently Asked Questions about typescript-circular-dependency

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

FAQPage Schema
Why do I get a "Cannot access X before initialization" runtime error in my TypeScript project?

Circular dependencies in TypeScript cause partially initialized modules, triggering runtime errors like "Cannot access X before initialization" or undefined imports. This Skill detects those import cycles in project dependency graphs and provides concrete refactoring strategies to resolve them.

How do I find and fix circular dependencies in a JavaScript project?

You analyze the project dependency graph using Madge to visualize import cycles, then apply resolution strategies like extracting shared interfaces, introducing dependency injection, using type-only imports, or reworking barrel files to break the import cycles.

What is the best way to resolve import cycles involving barrel files in TypeScript?

The best way to resolve import cycles involving barrel files in TypeScript is to rework the barrel file imports. By adjusting barrel file structures and extracting shared interfaces, you eliminate redundant module loading paths that cause circular dependencies.

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

Yes, you can use type-only imports to break circular dependencies in TypeScript. By importing only types without runtime code, you prevent the module execution cycle while still sharing interface definitions across files.

Does dependency injection help with resolving circular dependencies?

Dependency injection helps resolve circular dependencies by inverting the dependency direction. Introducing dependency injection separates module initialization from its usage, effectively breaking the import cycle in TypeScript or JavaScript projects.

How do I visualize circular dependency graphs in a codebase?

You visualize circular dependency graphs in a codebase by installing and running Madge. This dependency graph analysis tool detects and displays import cycles, allowing you to identify problematic service-to-service or barrel file patterns before applying fixes.