Cannot assign to read only property 'name' of object 'Error: Error finding the referenced node' when trying to access previous run of the node

Describe the problem/error/question

Hello, I have problem since version 1.105 (presumably) that i have code node that needs information from its previous run (its inside of the loop). It was working so far without issues (last run i did was on 30th July], but today when i’ve run it i encounter error

Cannot assign to read only property 'name' of object 'Error: Error finding the referenced node'

I debugged the problem down to the code:
$('Increment invoice nr').all(0,index-1)[0]

The node is calling its own previous execution and it was working fine before but now it triggers an error.

What is the error message (if any)?

Cannot assign to read only property 'name' of object 'Error: Error finding the referenced node'

Please share your workflow

This is the code of that node:

let input = $input.first();
console.log("test input",input);

let index = $runIndex;

const initialNumber = $('Set last invoice number').first().json.invoiceNumber;

console.log($('Set last invoice number').first().json.invoiceNumber);
console.log("index ",index);

if ($runIndex >0) {
  console.log("prev run below");
  console.log("prev run", $('Increment invoice nr').all());
  
  if (input.json.error) {
    input.json.invoiceNumber = $('Increment invoice nr').all(0,index-1)[0].json.invoiceNumber
    return input;
  }
  
  console.log('invoicenr: '+$('Increment invoice nr').all(0,index-1)[0].json.invoiceNumber);
  input.json.invoiceNumber = $('Increment invoice nr').all(0,index-1)[0].json.invoiceNumber+1
} else {

  if (input.json.error) {
    input.json.invoiceNumber = initialNumber
    return input;
  }
  
  input.json.invoiceNumber = initialNumber + 1;
  console.log('invoicenr from initial: ',input.json.invoiceNumber);
}

return input;

Information on your n8n setup

  • n8n version: 1.105.3
  • Running n8n via: n8n cloud
1 Like

Hey @Andrzej

Good catch! It seems in v1.105, nodes can no longer able to reference themselves and therefore no longer to reference previous runs when in a loop. I just tested with my examples I posted a while ago here Fun with Loops: Accumulating Results for Items and was able to reproduce the error.

You may want to consider discarding the loop node and doing the looping logic entirely within the code node instead.

1 Like

thats not really an option since there is way more nodes in between. i found other way to handle that but the question is there: is this expected change or a bug that was introduced with recent version?

1 Like

same here, we have lots of workflows that use this feature

I implemented something new, and I have the same problem at some code node. Some nodes before work with the same code literally. I have no idea what kind of bug this is.

Version 1.117.3 Selfhosted. I didn’t get the solution here for the problem and what is helping: Cannot assign to read only property 'name' of object 'Error: Referenced node is unexecuted'

@Jim_Le I don’t have a loop, only an if node. Is it the same problem?

I don’t get why I can log it without problems but not use it in a variable or anything else then.