1

I'm trying to require Dagre in Node (following the documentation on the Dagre wiki) after installing Dagre with NPM. Why isn't this working?

$ npm install dagre
dagre@0.5.0 node_modules/dagre
├── graphlib@0.8.0
└── lodash@2.4.1

$ echo -e "var dagre = require('dagre');\nvar g = new dagre.graphlib.Graph();" > app.js

$ node app.js 
/home/username/projects/dagretest/app.js:2
var g = new dagre.graphlib.Graph();
                          ^
TypeError: Cannot read property 'Graph' of undefined
    at Object.<anonymous> (/home/username/projects/dagretest/app.js:2:27)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
gaitat
  • 12,449
  • 4
  • 52
  • 76
  • I'm wondering if the documentation on that wiki is bogus, and needs to be corrected. – Jerrik Osvald Ansgar Oct 06 '14 at 22:06
  • The examples in the wiki that mention `dagre.graphlib.Graph()` do seem to be out-dated for `0.5.0`. You'll likely find more current examples within the [project's test cases](https://github.com/cpettitt/dagre/blob/v0.5.0/test). The [`layout-test.js`](https://github.com/cpettitt/dagre/blob/v0.5.0/test/layout-test.js) shows obtaining `Graph` directly from [`graphlib`](https://www.npmjs.org/package/graphlib) -- `require('graphlib').Graph` – Jonathan Lonowski Oct 06 '14 at 22:17

0 Answers0