Locate circular dependencies in TypeScript modules

Andrejs Abrickis
2 min readJun 11, 2018


Lately, I was researching how to compile Angular@6 project using angular-compiler - ngc. And found out that one of a reason an Angular project could fail to compile are circular dependencies in TypeScript files. After a quick research, I found a great developer tool madge which allows finding such dependencies.

Madge is a developer tool for generating a visual graph of your module dependencies, finding circular dependencies, and give you other useful info.

Let’s take a look on a trivial example where we have two TypeScript modules depending on each other.

ModuleA depends on ModuleB.


And ModuleB with dependency on ModuleA.


By running a cli command npx madge --circular --extensions ts ./ we can quickly get a list of circular dependencies of all.ts files in current directory and its subdirectories.

A circular dependency found: moduleA depends on moduleB

That's it! Now you see where you have circular dependencies and can go and fix it.

I hope you will find this little hint useful and it will help you to improve the quality of your TS projects. I encourage you to explore the tool as it provides much more than just circular dependency finding. And see how you could incorporate it in your web development process.

If you found this post useful and would like to read more about random web development topics, just clap for this article or drop a comment here. And as always you can find me on Twitter@andrejsabrickis

And if you are looking for new career opportunities, take a look at our open positions at KASKO.io. Join us and let’s reshape the multi-trillion dollar insurance world together.