Skip to content

jscycles

Find circular imports in JavaScript and TypeScript, between files and between the packages of a monorepo. One native binary that resolves imports like TypeScript and runs in well under a second.
Terminal window
npm install --save-dev jscycles
npx jscycles

On a checkout of ts-morph:

jscycles packages
✓ No inter-package cycles
✗ @ts-morph/common: 2 cycles
src/collections/SortedKeyValueArray.ts -> src/utils/index.ts -> … -> src/collections/SortedKeyValueArray.ts
src/typescript/index.ts -> src/typescript/tsInternal.ts -> src/typescript/index.ts
✗ ts-morph: 3 cycles
…
src/Project.ts -> src/ProjectContext.ts -> src/Project.ts
Summary: 3 packages, 2 with file cycles (5 total), 0 inter-package cycles

The exit status is 1, so a CI step fails until the cycles are fixed.

File and package cycles

Loops between files inside each package, and between the packages of an npm, yarn, pnpm or bun workspace. One representative loop per tangle, so the report is a to-do list rather than thousands of overlapping paths.

Resolves like TypeScript

Path aliases, extends chains through node_modules, declaration files, and .js specifiers that point at .ts sources. Optionally ignores imports that only carry types.

Never a false clean

Exit status 0 means no cycles, 1 means cycles, 2 means the scan could not finish. A file that cannot be parsed fails the scan instead of leaving a hole in the graph.

Fast, with no runtime

A single Rust binary that parses with tree-sitter in parallel. Prebuilt for Linux (static, Alpine too), macOS and Windows; nothing runs at install time, and it never touches the network.

nest1,068 files
jscycles0.08 s
madge2.04 s
dpdm0.86 s
typeorm3,609 files
jscycles0.28 s
madge2.97 s
dpdm1.48 s
excalidraw631 files
jscycles0.11 s
madge2.63 s
dpdm0.87 s
ts-morph1,171 files
jscycles0.08 s
madge1.64 s
dpdm0.83 s
Time to find cycles in each repository's packages directory; shorter is faster. Median of five runs on an Apple M3 Pro. Method and table.