2.0.1 • Public • Published

Cyclic reference detection


This application is meant to solve circular dependencies issues. To do so, it will scan hard dependencies

hard dependencies -> dependencies that need to be resolved during the parse of the module (i.e. every thing imported that is in the global scope of the file):

  • A reference to a class, function or variable in the global scope
  • An inheritance to a class
  • An initialized static variable
  • a decorator and its parameters

If theses hard dependencies form a DAG, then it extracts a topological order for the loading of the modules. Otherwise, throw "cyclic graph of hard dependencies" exception. This order can be stored in a namespace (a file containing all the import), or inside each module (the loading order is not ensured).


Detecting which dependencies are needed to form the global scope can be reduced to the halting problem (impossible in the general case). So this library look only top level declaration. If a function is called from the global scope, its body is not analyzed.

class A { static b: B } // global scope depends B

function AMixin() { return class { static b: B}; }
const A = AMixin(); // global scope doesn't depend on B as content of `AMixin` in not scanned


Backup your files before executing this command.

npm run start -- <tsConfigPath> <globalNamespacePath> <format> [graphHardDependenciesPath]
  • tsConfigPath (required): the full path of the tsconfig.json (or of the project. The file must exist
  • globalNamespacePath (required): the full path of the file that will order the imports
  • format (required): format imports in each file (Experimental, set it to false if unsure)
  • graphHardDependenciesPath (optional): if there are some cycles in the graph of hard dependencies, this program will generate a .gml file highlighting the strongly connected component that you must break. .gml file can be opened with yEd.


to display the graph :

  1. select all node (ctrl+a)
  2. Tools -> fit Node to Label
  3. Layout -> Organic -> Preferred Edge Length: 125


  • internal import must be relative i.e.
    • import { Document } from "src/toto" Not OK
    • import { Document } from "./src/toto" OK
  • the dependencies of the target project must be installed (with npm instal for example).
  • if you get a [warning], correct the import so that it import the globalNamespace and not directly a file


DownloadsWeekly Downloads






Unpacked Size

74.8 kB

Total Files


Last publish


  • diademe