Unknown error in Code node

I am getting an “Unknown Error” from the code node in my workflow. The error is very vague
Problem in node ‘Extract LogoPhoto: Unknown error

However, I was able to narrow it down to a few symptoms:
1- The error goes away if I remove the Set Variables node, i.e. the code node is directly connected to the Inputs webhook
2- The error goes away if I change the first line of the code node from
const item = $(‘Inputs’).first();
To
const item = $(‘Inputs’).all();
However, the output is wrong
3- The error goes away if i remove the await line in the code node and the output of the code node is correct with const item = $(‘Inputs’).first();

I have no way of debugging this further and can use some help!

Workflow


Information on your n8n setup

  • n8n version: 2.1.2
  • Database (default: SQLite): None
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Ubuntu

As you said, I would change the first line to const item = $(‘Inputs’).first();I would also change line 14 from what you have it as to const base64Data = item.binary[logoKey].data;

Changing the first line to use $(‘Inputs’).all() instead of first() returns an empty json output.

[
  {
    "files": []
  }
]

Changing line 14 to use data instead of getBinaryDataBuffer() no longer works in version 2.X (used to work in older n8n versions). And according to n8n documentation, this is the recommended way. This is what I get when using your suggestion which is incorrect.

[
  {
    "files": [
      {
        "fileName": "IMG_0075.PNG",
        "mimeType": "image/png",
        "base64Image": "filesystem-v2"
      }
    ]
  }
]

I apologize, I’m not the best with JSON.

what about keeping line 1 as the item first, but changing line 14 to let base64Data = await item.binary[logoKey].getBuffer();

Change $(‘Inputs’) to $input since your Code node receives data from the directly connected Set Variables node (which passes through the binary data)

const item = $input.first(); // Changed from $(‘Inputs’).first()

if (!item.binary) {
return [{ json: { files: } }];
}

const binaryData = item.binary;
const allFiles = ;

const logoKey = ‘logoPhoto’;
if (binaryData[logoKey]) {
let base64Data = await this.helpers.getBinaryDataBuffer(0, logoKey);
const base64String = base64Data.toString(‘base64’);

allFiles.push({
    fileName: binaryData[logoKey].fileName,
    mimeType: binaryData[logoKey].mimeType,
    base64Image: base64String,
});

}

return [{ json: { files: allFiles } }];

Error
this.helpers.getBuffer is not a function [line 14]

My code node is not getting input directly from the previous node. There are nodes in the middle, the Set Variables node shown is the node in the middle in this workflow, so $input will not work

your set node is off, so it isnt sending any other fields needed. Turn it on, and then you can also try this code.

const item = $('Inputs').first(); 

if (!item.binary) {
    return [{ json: { files: [] } }];   
}  

const binaryData = item.binary;
const allFiles = [];
const logoKey = 'logoPhoto';

if (binaryData[logoKey]) {
    const base64Data = item.binary[logoKey].data;
    allFiles.push({
        fileName: binaryData[logoKey].fileName,
        mimeType: binaryData[logoKey].mimeType,
        base64Image: base64Data,
    });
}

return [{ json: { files: allFiles } }];
1 Like

Good catch. Turning “Include Other Input Fields” on helps solve the problem with this mini example. However, in my real workflow, there are several other nodes in the middle, like HTTP node, an IF node, a data table node. None of those nodes have an option to let the binary file pass through.

Can you use the https node to get the binary from the webhook URL after the IF node? or you can refrence the webhooks binary

unfortunately that didn’t work. I ended up moving nodes around to get around this error. I honestly think there is an n8n bug somewhere in the new version (2.X) because this workflow has been working just fine for months with n8n 1.X

I don’t believe it’s a bug, N8N V2 just changed a lot of things but at least you solved it!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.