blader/claudeception/typescript-circular-dependency
Claude Code and agent skill by blader/claudeception
- community
Checking that the SKILL.md file is still in the repository.
Detect and resolve TypeScript/JavaScript circular import dependencies. Use when: (1) "Cannot access 'X' before initialization" at runtime, (2) Import returns undefined unexpectedly, (3) "ReferenceError: Cannot access X before initialization", (4) Type errors that disappear when you change import order, (5) Jest/Vitest tests fail with undefined imports that work in browser.
Install
npx vskill@latest install blader/claudeception/typescript-circular-dependencySKILL.md
TypeScript Circular Dependency Detection and Resolution
Problem
Circular dependencies occur when module A imports from module B, which imports (directly or indirectly) from module A. TypeScript compiles successfully, but at runtime, one of the imports evaluates to undefined because the module hasn't finished initializing yet.
Context / Trigger Conditions
Common error messages:
Symptoms that suggest circular imports:
- Import is
undefinedeven though the export exists - Error only appears at runtime, not during TypeScript compilation
- Moving an import statement changes which import is undefined
- Tests fail but the app works (or vice versa)
- Adding
console.logat the top of a file changes behavior
Solution
Step 1: Detect the Cycle
Use a tool to visualize dependencies:
Or use the TypeScript compiler:
Step 2: Identify the Pattern
Common circular dependency patterns:
Pattern A: Service-to-Service
Pattern B: Type imports
Pattern C: Index barrel files
Step 3: Resolution Strategies
Strategy 1: Extract Shared Dependencies
Before:
After:
Strategy 2: Dependency Injection
Strategy 3: Dynamic Imports
Strategy 4: Use Type-Only Imports
If you only need types (not values), use type-only imports:
Strategy 5: Restructure Barrel Files
Before (problematic):
After:
Step 4: Prevent Future Cycles
Add to your CI/build process:
Or configure ESLint:
Verification
- Run
madge --circular src/- should report no cycles - Run your test suite - previously undefined imports should work
- Delete
node_modulesand reinstall - app should still work - Build for production - no runtime errors
Example
Problem: OrderService is undefined when imported in UserService
Detection:
Fix: Extract shared interface
Notes
- TypeScript
import typeis your friend—it's erased at runtime and can't cause cycles - Barrel files (
index.ts) are a common source of accidental cycles - The order of exports in a file can matter when there's a cycle
- Jest/Vitest may handle module resolution differently than your bundler
- Some bundlers (Webpack, Vite) have better cycle handling than others
require()can sometimes mask circular dependency issues thatimportexposes
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingexamples/typescript-circular-dependency/SKILL.md
Popularity
- 7-day trend score
- 0
Refreshed 19 Mar 2026, 8 months ago.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/blader/claudeception/typescript-circular-dependency)