Detecting Circular Imports with Madge (and Locking Down Regressions in Lint)

Anyone who has spent hours chasing an undefined in the middle of a bundle or a strange behavior only in production knows how an unresolved import chain can become a headache. One of the frequent culprits is the circular import: module A imports B, B imports C, and somewhere in the chain someone imports A again — closing a cycle.
It's wonderful — the build works, the project runs locally, but when you try to deploy, it breaks! \o/
I've seen this in small projects and in large ones; the only difference is the size of the problem you'll face. You can spot the headache with Madge and it's a lifesaver!
To lock up TypeScript, a circular import is a treat.




