typescript-circular-dependency

Detect and resolve circular import dependencies in TypeScript and JavaScript projects.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/PhamMinhHaiAu-12035071/cursor-pro-max --skill typescript-circular-dependency-phamminhhaiau-12035071
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: typescript-circular-dependency
Source: https://github.com/PhamMinhHaiAu-12035071/cursor-pro-max/tree/main/.claude/skills/claudeception/examples/typescript-circular-dependency
Command: npx skills add https://github.com/PhamMinhHaiAu-12035071/cursor-pro-max --skill typescript-circular-dependency-phamminhhaiau-12035071

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Circular import dependencies in TypeScript and JavaScript projects often lead to runtime errors or undefined values during initialization. This Skill helps you detect and resolve these cycles to ensure reliable module loading.

Core Features & Use Cases

  • Cycle detection for common TS/JS patterns (service-to-service, barrel/index file cycles, and cross-package graphs).
  • Practical resolution strategies: extract shared interfaces, dependency injection, dynamic imports, type-only imports, and barrel-file restructuring.
  • Use Case: when a runtime error references cannot access before initialization or undefined imports caused by cyclic graphs.

Quick Start

Run a cycle-detection workflow on your TS/JS project to identify cycles, then apply the suggested fixes to break the cycles and stabilize initialization.

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 cannot access before initialization errors in TypeScript?

These errors usually indicate circular import dependencies in your TypeScript or JavaScript module graph, where modules reference each other cyclically before fully initializing. You can detect these cycles using madge or TS compiler cycle checks.

How do I detect circular dependencies in a JavaScript project?

You detect circular dependencies by running cycle-detection tools like madge or the TypeScript compiler's cycle checks against your module graph. This identifies service-to-service, barrel-file, or cross-package cycles causing undefined imports.

What is the best way to resolve circular imports caused by barrel files?

The best way to resolve barrel-file circular imports is by restructuring the barrel files or extracting shared interfaces. You can also use type-only imports or dynamic imports to break the initialization cycles.

Can I use dependency injection to fix TypeScript circular dependencies?

Yes, dependency injection is a supported strategy to resolve TypeScript circular dependencies. It breaks cyclic graphs by inverting the dependency chain, preventing modules from importing each other directly during initialization.

Does this approach work for cross-package module graphs?

Yes, cycle detection and resolution strategies apply to cross-package module graphs in TypeScript and JavaScript projects. This ensures reliable module loading across different packages within the same project structure.

When should I use type-only imports to fix circular dependencies?

Use type-only imports to fix circular dependencies when modules only need each other's types for compilation, not runtime values. This prevents the modules from entering the runtime initialization cycle while maintaining type safety.