typescript-circular-dependency

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

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you diagnose and resolve TypeScript and JavaScript circular import problems that only appear at runtime, even when the code compiles cleanly.

Core Features & Use Cases

  • Cycle Detection: Identifies import loops that cause undefined exports, initialization errors, and flaky test behavior.
  • Resolution Guidance: Recommends practical fixes such as extracting shared types, using dependency injection, switching to type-only imports, or replacing barrel-file imports with direct paths.
  • Prevention Workflow: Shows how to add cycle checks to CI and linting so the same dependency issues do not return.
  • Use Case: A service works in one environment but fails in tests with "Cannot access before initialization"; this Skill helps trace the loop and restructure the modules safely.

Quick Start

Ask the assistant to inspect your TypeScript imports for circular dependencies and propose the smallest safe refactor to eliminate the runtime error.

Frequently Asked Questions about typescript-circular-dependency

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

FAQPage Schema
Why does TypeScript compile cleanly but throw a runtime initialization error?

TypeScript compiles cleanly but throws a runtime initialization error because circular import dependencies create initialization loops where modules reference each other before fully loading. This Skill detects these import cycles and recommends extracting shared types or using type-only imports to resolve the undefined exports.

How do I fix circular import dependencies in a JavaScript codebase?

To fix circular import dependencies in a JavaScript codebase, this Skill analyzes the import loops and proposes the smallest safe refactor, such as switching to type-only imports, applying dependency injection, or replacing barrel-file imports with direct paths to eliminate the runtime failures.

What causes flaky test behavior with 'Cannot access before initialization' in services?

Flaky test behavior with 'Cannot access before initialization' in services is caused by circular import dependencies that disrupt module loading order. This Skill traces the import loops in your components and shared types, providing resolution guidance to restructure the modules safely.

How can I prevent circular dependencies from returning in a TypeScript project?

To prevent circular dependencies from returning in a TypeScript project, this Skill demonstrates how to add cycle checks to your CI pipelines and linting workflows, ensuring that import loops and barrel-file import issues are caught before they cause runtime errors.

Does this approach work for resolving barrel-file import loops in shared types?

Yes, this approach works for resolving barrel-file import loops in shared types by analyzing the module resolution paths, identifying the specific cycles causing flaky test behavior, and recommending direct path imports or type-only imports to break the dependency loops.