dagre: Cannot set property 'order' of undefined
Greetings. I am seeing the following error:
TypeError: Cannot set property 'order' of undefined
at dagre.core.js:1395
at arrayEach (lodash.js:1289)
at Function.<anonymous> (lodash.js:3345)
at dagre.core.js:1394
at arrayEach (lodash.js:1289)
at Function.<anonymous> (lodash.js:3345)
at assignOrder (dagre.core.js:1393)
at order (dagre.core.js:1371)
at dagre.core.js:495
at notime (dagre.core.js:2897)
After doing some debugging I see the following:
function assignOrder(g, layering) {
_.each(layering, function(layer) {
_.each(layer, function(v, i) {
g.node(v).order = i;
});
});
}
In this function layer is an array, seemingly containing strings (maybe id’s). When this error crops up, it seems that several items in the layer array are undefined. Therefore g.node(undefined) also returns undefined and produces the error.
I am currently going through our code to see what might be causing the issue, but was hoping that maybe the authors had some insight into what I might look for.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 38
@mmacfadden thanks to your reproducer and some guesswork i think i found out the problem.
Let me explain, the problems seems to be related to the way
lodashforEachworks, the methodutil.buildLayerMatrixbuilds a matrix, but the orders assigned there (layering[rank][node.order] = v;) are not always consecutive, so it ends up with a matrix with “holes” between orders.forEachmethods seems to iterate over theseundefinedvalues in theassignOrderand thus the reported exception.See a reproducer of what i mean:
This yields:
@Revadike, it’s likely because this project has no maintainer, as announced in the README.
For people that come here later, at least in my case, I found the issue and it was a really easy fix. When I add a node, I track the host field associated with it and do grouping so that all nodes with the same host are grouped together.
However, I was doing some dummy data and the host field was blank, i.e.
"". For whatever reason, this caused that error. I go back and set the host field for my data to be a >0 length string, and everything is working again. Hopefully that’ll be enough to help somebody since it doesn’t seem like this library is every gonna be updated again 😦I am also having this issue. I’m using
react-create-app, so it’s not easy to adjust build settings per @xnt 's suggestion. Any word on a fix?I’m using dagre
0.8.5Thanks a bunch!
EDITS: grammar, included a version number