生成 dot 图需额外安装 GraphViz 的 dot 命令;v12 及更早版本需手动传 --config 才能找到配置文件;pnpx 语义与 npx 差异较大,使用前需留意
dependency-cruiser
sverweijMIT活跃维护校验并可视化 JavaScript、TypeScript 等项目的模块依赖,按自定义规则拦截循环依赖和违规引用,把架构约束变成可执行的检查。
Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
npm install --save-dev dependency-cruiser
npx dependency-cruiser --initREADME 未说明
用自定义规则校验并可视化 JS/TS 项目依赖,提前发现循环依赖和越界引用
校验并可视化 JavaScript、TypeScript 等项目的模块依赖,按自定义规则拦截循环依赖和违规引用,把架构约束变成可执行的检查。
核心能力
- 按自定义规则校验依赖并报告违规项
- 检测循环依赖、缺失依赖、孤儿模块等问题
- 输出 dot、mermaid、json、csv、html 等多种格式
- 支持 JS、TS、CoffeeScript、LiveScript 及 ES6/CommonJS/AMD
- 内置 --init 交互式生成项目专属配置文件
容易踩的坑
- v18.7.2最新正式版2026-11-02 · 2026-11-02 21:21 UTC
🐛 fixes
- e65bb5b4 fix(extract/resolve): adds correctly handling 'bundledDependencies: true' (#1120) thanks to @sebdanielsson for finding and filing the issue that led to this fix.
👷 maintenance
- 4e2daa02 fix(manifest): updates contributor list with recent contributors
- a37c1cf6 chore(test): bumps minimum branch coverage up to current HWM
- 1ecdae89 build(npm): updates external dependencies
- v18.8.0-beta-2pre-release2026-11-01 · 2026-11-01 23:49 UTC
查看更新说明
✨ features
- 0b8b47d4 feat(extract): adds support for typescript >=7.1 (the native compiler) [AI] - thanks to @buko106 for the pull request
This release updates the beta with fixes done in the main branch (npm: latest tag) in 18.7.1, which, for completeness sake are:
🐛 fixes
- 2a46eecf fix(main/resolve-options): resolves tsconfig paths without baseUrl from the tsconfig directory (#1116) Thanks to @thirtytwobits for raising the issue and @Johannes7549 for making the fixing pull request!
- fd7889bf fix(extract/transpile): passes the file name to the typescript transpiler to prevent it choking on imports from './module' (#1118). Thanks to @sebdanielsson for reporting the issue, finding the root cause and baking the fixing PR!
👷 maintenance
- 00ca161c build(npm): updates external dependencies
- 96a1dd35 doc(README): removes broken link
- c5b97371 chore(npm): refreshes lock-file
- dbe5e74e chore(Gort): makes agent instruction even more explicit
- 5adda5b2 chore(gha): replaces last remnant of yarn with node --run
- deea6a17 doc: corrects type references in jsdoc
- v18.7.12026-11-01 · 2026-11-01 23:37 UTC
查看更新说明
🐛 fixes
- 2a46eecf fix(main/resolve-options): resolves tsconfig paths without baseUrl from the tsconfig directory (#1116) Thanks to @thirtytwobits for raising the issue and @Johannes7549 for making the fixing pull request!
- fd7889bf fix(extract/transpile): passes the file name to the typescript transpiler to prevent it choking on imports from './module' (#1118). Thanks to @sebdanielsson for reporting the issue, finding the root cause and baking the fixing PR!
👷 maintenance
- 00ca161c build(npm): updates external dependencies
- 96a1dd35 doc(README): removes broken link
- c5b97371 chore(npm): refreshes lock-file
- dbe5e74e chore(Gort): makes agent instruction even more explicit
- 5adda5b2 chore(gha): replaces last remnant of yarn with node --run
- deea6a17 doc: corrects type references in jsdoc
Note for those eagerly awaiting typescript 7.1 support - thanks to @buko106 there's a dependency-cruiser (beta) version that works with typescript 7.1 beta . The fixes in this (18.7.1) release combined with 7.1 beta support will be published as 18.8.0-beta-2.
- v18.8.0-beta-1pre-release2026-10-23 · 2026-10-23 18:23 UTC
查看更新说明
✨ features
- 0b8b47d4 feat(extract): adds support for typescript >=7.1 (the native compiler) [AI] - thanks to @buko106 for the pull request
- v18.7.02026-10-19 · 2026-10-19 19:43 UTC
查看更新说明
✨ features
- 6ae13a39 feat(summarize): makes the missing compiler warnings more precise (#1111)
This a.o. makes dependency-cruiser stop reporting a missing typescript compiler even when
swcwas installed (and swc was sufficient for the configured features). Thanks @duvillierA for raising the issue!
🐛 fixes
- da0efbb4 fix(extract/resolve): disregards peerDependenciesMeta and similar actual non-dependencies keys to prevent false positives (#1110). Thanks @arvidtorbjoernsen for reporting the issue that led to this fix!
- c580daf6 fix(extract/swc): expands extensions swc can handle to all ts* variants (#1105) Thanks @duvillierA for raising the issue and for providing the fix that landed in the PR!
- 9d53b95a fix(extract/swc): adds recognition of type-only-ness of exports (#1106). Thanks @duvillierA for raising the issue and for providing the fix that landed in the PR!
📖 documentation
- 8b4dbdee docs: fix typo in no-duplicate-dep-types comment (#1108) Thanks @Samathingamajig for the PR!
- 6ae13a39 feat(summarize): makes the missing compiler warnings more precise (#1111)
This a.o. makes dependency-cruiser stop reporting a missing typescript compiler even when
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
Dependency cruiser 
Validate and visualise dependencies. With your rules. JavaScript. TypeScript. CoffeeScript. ES6, CommonJS, AMD.
What's this do?

This runs through the dependencies in any JavaScript, TypeScript, LiveScript or CoffeeScript project and ...
- ... validates them against (your own) rules
- ... reports violated rules
- in text (for your builds)
- in graphics (for your eyeballs)
As a side effect it can generate dependency graphs in various output formats including cool visualizations you can stick on the wall to impress your grandma.
How do I use it?
Install it ...
npm install --save-dev dependency-cruiser
# or
yarn add -D dependency-cruiser
pnpm add -D dependency-cruiser
... and generate a config
npx dependency-cruiser --init
This will look around in your environment a bit, ask you some questions and create
a .dependency-cruiser.js configuration file attuned to your project12.
Show stuff to your grandma
To create a graph of the dependencies in your src folder, you'd run dependency
cruiser with output type dot and run GraphViz dot3 on the result. In
a one liner:
npx dependency-cruiser src --include-only "^src" --output-type dot | dot -T svg > dependency-graph.svg
While not necessary from dependency-cruiser v13 and later, in v12 and older you'll have to pass the --config option to make it find the .dependency-cruiser.js configuration file:
npx dependency-cruiser src --include-only "^src" --config --output-type dot | dot -T svg > dependency-graph.svg
- You can read more about what you can do with
--include-onlyand other command line options in the command line interface documentation. - Real world samples contains dependency cruises of some of the most used projects on npm.
- If your grandma is more into formats like
mermaid,json,csv,htmlor plain text we've got her covered as well.
Validate things
Declare some rules
When you ran dependency-cruiser --init above, the command also added some rules
to .dependency-cruiser.js that make sense in most projects, like detecting
circular dependencies, dependencies missing in package.json, orphans,
and production code relying on dev- or optionalDependencies.
Start adding your own rules by tweaking that file.
Sample rule:
{
"forbidden": [
{
"name": "not-to-test",
"comment": "don't allow dependencies from outside the test folder to test",
"severity": "error",
"from": { "pathNot": "^test" },
"to": { "path": "^test" }
}
]
}
- To read more about writing rules check the writing rules tutorial or the rules reference
Report them
npx dependency-cruiser src
While not necessary from dependency-cruiser v13, in v12 and older you'll have to pass the --config option to make it find the .dependency-cruiser.js configuration file:
npx dependency-cruiser --config .dependency-cruiser.js src
This will validate against your rules and shows any violations in an eslint-like format:

There's more ways to report validations; in a graph (like the one on top of this
readme) or in an self-containing html file.
- Read more about the err, dot, csv and html reporters in the command line interface documentation.
- dependency-cruiser uses itself to check on itself in its own build process;
see the
depcruisescript in the package.json
I want to know more!
You've come to the right place :-) :
- Usage
- Hacking on dependency-cruiser
- Other things
License
Thanks
- Marijn Haverbeke and other people who collaborated on acorn - the excellent JavaScript parser dependency-cruiser uses to infer dependencies.
- Katerina Limpitsouni of unDraw for the ollie in dependency-cruiser's social media image.
- All members of the open source community who have been kind enough to raise issues, ask questions and make pull requests to get dependency-cruiser to be a better tool.
Build status
Made with :metal: in Holland.
Footnotes
-
We're using
npxin the example scripts for convenience. When you use the commands in a script inpackage.jsonit's not necessary to prefix them withnpx. ↩ -
If you don't want to use
npx, but insteadpnpx(from thepnpmpackage manager) oryarn- please refer to that tool's documentation. Particularlypnpxhas semantics that differ fromnpxquite significantly and that you want to be aware of before using it. In the meantime:npxshould work even when you installed the dependency with a package manager different fromnpm. ↩ -
This assumes the GraphViz
dotcommand is available - on most linux and comparable systems this will be. In case it's not, see GraphViz' download page for instructions on how to get it on your machine. ↩