question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot set property 'order' of undefined

See original GitHub issue

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.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:38

github_iconTop GitHub Comments

2reactions
josejuliocommented, Jun 22, 2018

@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 lodash forEach works, the method util.buildLayerMatrix builds 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. forEach methods seems to iterate over these undefined values in the assignOrder and thus the reported exception.

See a reproducer of what i mean:

var _ = require("lodash");

var arr = [];
arr[0] = 0;
arr[1] = 1;
arr[4] = 4;
arr[5] = 5;

console.log(arr);

console.log('for var i in arr:');
for (var i in arr) {
    console.log(`arr[${i}] = ${arr[i]}`);
}

console.log('_forEach:');
_.forEach(arr, function(v, i) {
    console.log(`arr[${i}] = ${v}`);
});

This yields:

[ 0, 1, <2 empty items>, 4, 5 ]
for var i in arr:
  arr[0] = 0
  arr[1] = 1
  arr[4] = 4
  arr[5] = 5
_forEach:
  arr[0] = 0
  arr[1] = 1
  arr[2] = undefined
  arr[3] = undefined
  arr[4] = 4
  arr[5] = 5
1reaction
gordonwoodhullcommented, Jun 27, 2022

@Revadike, it’s likely because this project has no maintainer, as announced in the README.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript - cannot set property of undefined - Stack Overflow
I get the following error: Uncaught TypeError: Cannot set property 'greeting' of undefined. I'm trying to do something similar to an associative ...
Read more >
How to solve the 'cannot set property of undefined' issue on ...
To access an object key the object has to exist. When it doesn't and you try to access the key, you get the...
Read more >
TypeError: Cannot set properties of Undefined in JavaScript
The "Cannot set properties of undefined" error occurs when setting a property on an undefined value. To solve the error, conditionally check if...
Read more >
Uncaught TypeError: Cannot set property
In JavaScript if a variable has been declared, but has not been assigned a value, is automatically assigned the value undefined . Therefore,...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
What Causes TypeError: Cannot Read Property of Undefined ... Undefined means that a variable has been declared but has not been assigned a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found