Skip to content

Madge

Draws a graph of your JavaScript module dependencies and finds circular ones.

Stars
10.2k
Forks
349
Licence
MIT
Language
JavaScript
Last update
10 months ago
Type
Dev tool

What it is

Madge reads your source code and works out which files import which others, then shows that as a visual graph. It can also list circular dependencies, orphaned files, and modules with no dependencies. It works with CommonJS, AMD and ES6 modules, and with Sass, Stylus and Less files.

  • Run madge --circular on a source folder to list files that import each other in a loop
  • Generate an SVG graph of a project's modules with the .image() API method
  • Use --orphans to find files that nothing else imports
  • Use --depends to see which modules rely on a given file before refactoring it

Great for

  • JavaScript developers untangling a large codebase with many imports
  • Teams who want to catch circular dependencies before they cause bugs
  • Anyone who wants a picture of how a project's modules fit together
  • Projects that use CSS preprocessors like Sass, Stylus or Less

Not ideal for

  • Non-developers, since it runs from the command line or Node.js code
  • Projects that need dependency analysis for languages other than those listed in the README
  • Anyone wanting to generate images without Graphviz installed, since image output depends on it
Step-by-step guide: how to use MadgeInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Node.js and npm · Graphviz (optional, only for visual graph output)

    Install madge globally with npm

    npm -g install madge

    Install Graphviz on Mac OS X (optional)

    brew install graphviz || port install graphviz

    Install Graphviz on Ubuntu (optional)

    apt-get install graphviz
  2. 2

    Run it

    • Install madge with npm -g install madge
    • Run madge path/src/app.js to list dependencies of one file
    • Run madge --circular path/src/app.js to check for circular dependencies
    • Optionally install Graphviz and use the .image() API to save a graph
  3. 3

    Get the most out of it

    • Use a .madgerc file or a madge key in package.json to set options such as fontSize and rankdir
    • Use --extensions js,jsx to include more file types when scanning a folder
    • Use excludeRegExp or dependencyFilter to leave out parts of the tree you do not need
    • Use the API methods like circular(), orphans() and leaves() to build checks into scripts

Downloads

Strengths

  • Supports several module systems (AMD, CommonJS, ES6) and CSS preprocessors
  • Offers both a command-line tool and a Node.js API
  • Has a configuration file option (.madgerc or package.json) for styling the graph

Trade-offs

  • Image output requires Graphviz to be installed separately
  • The README is truncated here, so details on newer module syntax support are unclear
  • Relies on an external dependency-tree library for extraction, so edge cases depend on that library

How it compares

ProjectStarsTypeLevelUpdatedBest for
madge (this)10.2kDev toolbeginner10 months agoJavaScript developers untangling a large codebase with many imports
webpack-bundle-analyzer12.7kDev toolbeginner10 days agoFrontend developers trying to shrink a slow-loading webpack bundle
webpack66kDev toolintermediate4 days agoFrontend developers building single-page or multi-page web apps
parcel44kDev toolbeginner4 days agoWeb developers who want a bundler that works without a config file
prettier52.4kDev toolbeginner4 days agoTeams that want one shared code style without writing their own rules
babel44.1kDev toolintermediate4 days agoWeb developers who want to use recent JavaScript syntax while still supporting older browsers

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.