Registry / web-framework / dagre
library0.8.5jsnpmunverified

Dagre is a JavaScript library designed for laying out directed graphs programmatically on the client-side. The package `dagre` at version 0.8.5, which is the latest available on the public npm registry under this name, was last published over six years ago and is effectively abandoned. While the GitHub repository shows recent activity and releases (v2.x, v3.x), these are published under the `@dagrejs/dagre` scoped package. Users attempting to install `dagre` directly will receive the unmaintained 0.8.5 version. This library's core functionality relies on `graphlib` for graph data structures, and it is often paired with rendering libraries like D3 for visualization. Its primary purpose is to automatically compute optimal node and edge positions in directed graphs, differentiating it from manual layout tools.

npm install dagre
INSTALL
IMPORT
SIG · DAGRE
D
dagre
web-frameworkjavascriptv0.8.5
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dagre
✓ const dagre = require('dagre');
✗ import dagre from 'dagre';
For `dagre@0.8.5`, CommonJS `require` is the standard module import. ESM `import` is not supported in this version.
layout
✓ const dagre = require('dagre'); dagre.layout(graph);
✗ import { layout } from 'dagre';
The primary layout function is a method on the `dagre` object; it is not a named export in version 0.8.5.
Graph
✓ const graphlib = require('graphlib'); const g = new graphlib.Graph();
✗ import { Graph } from 'dagre';
Dagre operates on `graphlib.Graph` instances. `graphlib` must be imported separately.

This example demonstrates how to create a graph using `graphlib`, add nodes and edges, apply the `dagre` layout, and then retrieve the calculated positions for nodes and bend points for edges. It uses CommonJS `require` for compatibility with `dagre@0.8.5`.

const dagre = require('dagre'); const graphlib = require('graphlib'); // Create a new directed graph const g = new graphlib.Graph().setGraph({ rankdir: 'LR' // Layout direction: Left to Right }).setDefaultNodeLabel(() => ({})).setDefaultEdgeLabel(() => ({})); // Add nodes to the graph g.setNode('A', { label: 'Node A', width: 60, height: 30 }); g.setNode('B', { label: 'Node B', width: 60, height: 30 }); g.setNode('C', { label: 'Node C', width: 60, height: 30 }); g.setNode('D', { label: 'Node D', width: 60, height: 30 }); // Add edges to the graph g.setEdge('A', 'B', { label: 'AB' }); g.setEdge('B', 'C', { label: 'BC' }); g.setEdge('A', 'D', { label: 'AD' }); g.setEdge('C', 'D', { label: 'CD' }); // Run the layout algorithm dagre.layout(g); // Log node positions g.nodes().forEach(v => { const node = g.node(v); console.log(`Node ${v}: x=${node.x}, y=${node.y}`); }); // Log edge bend points (if any) g.edges().forEach(e => { const edge = g.edge(e); if (edge.points && edge.points.length > 0) { console.log(`Edge ${e.v}-${e.w} points:`, edge.points); } });
Debug
Known issues
breakingThe `dagre` package on npm (version 0.8.5) is effectively abandoned. Active development, including ESM support, TypeScript rewrite, and new features (versions 2.x and 3.x), has moved to the `@dagrejs/dagre` scoped package. Installing `dagre` will fetch the old, unmaintained version.
fix
For actively maintained and modern features, install `@dagrejs/dagre` instead: `npm install @dagrejs/dagre`.
affects: >=0.8.5
gotchaVersion `0.8.5` of `dagre` does not support ES Modules (ESM) syntax. Attempts to use `import dagre from 'dagre'` will result in errors in modern JavaScript environments.
fix
Use CommonJS `const dagre = require('dagre');` for module loading, or switch to the `@dagrejs/dagre` package for ESM support.
affects: 0.1.0 - 0.8.5
gotchaDagre requires the `graphlib` package for its graph data structures. It does not provide its own. Failing to install and use `graphlib` alongside `dagre` will lead to runtime errors when trying to create graphs.
fix
Ensure `graphlib` is installed (`npm install graphlib`) and imported/required separately to create graph objects (e.g., `new graphlib.Graph()`).
affects: >=0.1.0
deprecatedLoading `dagre` via a `<script>` tag that exposes a global `dagre` object is a legacy pattern and is not recommended for new projects. This method lacks dependency management and proper module encapsulation.
fix
Use a module loader (e.g., CommonJS `require` for `dagre@0.8.5`) or migrate to `@dagrejs/dagre` for modern ESM approaches.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: dagre.layout is not a function
Dagre was not correctly imported or loaded, or `graphlib` was not installed/imported, leading to `dagre` being `undefined` or not having the expected methods.
fix
Ensure `const dagre = require('dagre');` is used for CommonJS environments, or `dagre` is available globally if using a script tag. Also ensure `graphlib` is installed and its `Graph` class is used to create the graph object passed to `dagre.layout`.
Error: The "dagre" utility is a mandatory dependency.
This error often occurs when another library (like JointJS) explicitly checks for the global or module availability of `dagre` and cannot find it.
fix
Verify that `dagre` is properly installed (`npm install dagre`) and imported/required in your module system. For older `dagre` versions, ensure it's available in the global scope if your integrating library expects it that way.
Upgrade
Version history
0.8.5latest on npm
Audit
Dependencies
graphlibrequiredProvides the fundamental graph data structure (Graph) that Dagre operates on. Dagre computes layout for Graphlib instances.
Agent activity
8 hits · last 30 days
node
8
Resources
dagre — npm install dagre · libregistry