dagre icon indicating copy to clipboard operation
dagre copied to clipboard

Specific imports from dagre cause TypeError

Open everyday847 opened this issue 4 years ago • 0 comments

I'm in a Typescript project. I've installed dagre (via npm install dagre) and installed type definitions as well. I'd like to define a graph in a particular file, so I

import { graphlib } from 'dagre';
// ...
this._g = new graphlib.Graph();
this._g.setNode('foo', {label: 'bar'});
// ...

vscode seems to see nothing wrong at any point, suggesting that type annotations are checking out, and so forth. When I run unit tests for the file in question, the import appears to fail, with a remarkable backtrace:

  ● Test suite failed to run

    TypeError: Cannot read property 'preorder' of undefined

    > 4 | import { graphlib, layout } from 'dagre';
        | ^
      5 |


      at Object.<anonymous> (../node_modules/dagre/lib/rank/network-simplex.js:7:42)
      at Object.<anonymous> (../node_modules/dagre/lib/rank/index.js:6:22)
      at Object.<anonymous> (../node_modules/dagre/lib/layout.js:6:12)
      at Object.<anonymous> (../node_modules/dagre/index.js:26:11)

Looking at dagre/lib/rank/network-simplex.js line 7, it's

var preorder = require("../graphlib").alg.preorder;

so I suppose it's claiming that alg is undefined. I'm not exactly sure why this would be, or what an appropriate debugging workflow is: I don't have a deep understanding of the way that js/ts resolves dependencies. Thanks for any help you can offer.

everyday847 avatar May 12 '20 21:05 everyday847