n8n "The first argument must be of type string or an instance of Buffer ... Received undefined": What It Means and How to Fix It

The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined

"ERROR: The first argument must be of type string or an instance of Buffer..." has 17,823 views on the n8n forum (Nov 1, 2026) and no accepted answer; the last reply, in 2025, just asks whether anyone found a fix. The same error shows up with the HTTP Request node (t/191090, t/188909, t/27290), Gmail (t/159868) and AI model nodes (t/296649). This page explains what it means from n8n's source code and gives a fix for each cause.

How we checked: the n8n source at release 2.45.7 (Oct 30, 2026), n8n's docs, Node.js's Buffer docs and the forum threads linked. We reproduced the error message itself in Node.js 24, but we did not run each workflow case below in a live n8n instance. Where a cause comes only from a forum thread, we say so.

Sheets Bulk AI Runner Pro Kit: $19

Paid option: if your files end up as rows in a Google Sheet (file links, extracted text) and you run AI over each row, the bulk AI runner does it in batches and resumes where it stopped. The Pro Kit adds the Google Sheet header CSV, a 10-minute setup guide and an offline test kit (a local OpenAI, Google Sheets and Gmail mock with the 15-scenario runner), so you can watch the retries and resume work before you use a real API key. This guide stays free.

What the error actually means

"Buffer" here has nothing to do with the Buffer social media app. It's Node.js's type for raw bytes. The message comes from Node's Buffer.from() when it is called with undefined (Node.js Buffer docs). You can see it yourself: Buffer.from(undefined, 'base64') throws exactly this text, with the code ERR_INVALID_ARG_TYPE.

In n8n, files travel as binary data on each item: item.binary.<field>, usually item.binary.data. That object holds either the file content as a base64 string in data, or an id pointing to where n8n stored the file (filesystem, database or S3 mode). When a node needs the bytes, n8n's core does this (binary-data.service.ts):

if (binaryData.id) { /* read the stored file */ }
return Buffer.from(binaryData.data, 'base64');

The HTTP Request node does the same when it uploads a file (HttpRequestV3.node.ts; the stack trace in t/191090 points to exactly that line). So the error means: the binary field exists, but it has neither an id nor any data. There's an empty file object where n8n expected a file.

When the field is missing entirely, current n8n versions stop earlier with a clearer message: "This operation expects the node's input data to contain a binary file 'data', but none was found" or "The item has no binary field 'data'" (binary-helper-functions.ts). If you get the Buffer error instead, something created the field without content.

Which cause do you have?

What you noticeMost likely cause
The error comes right after a Code node that creates, renames or copies a fileCause 1: the Code node builds the binary object wrong
It works when the earlier nodes are pinned, and fails on a full runCause 1 (seen in t/27290)
Some items have a file and some don't (an If branch, emails without attachments, "no media" messages)Cause 2: an empty placeholder file
The file comes from an earlier node, not the node directly before, or through a MergeCause 3: the file is on a different item
Edit Image fails on some images onlyCause 4: the image tool produced nothing
The stack trace points at a line in your own Code nodeCause 5: your code calls Buffer.from() on a missing field

Cause 1: a Code node builds the binary object wrong

The most common pattern in the forum threads: a Code node returns something like binary: { data: { fileName, mimeType } }, or { data: item.json.base64 } where base64 is the wrong field name, so data ends up undefined. The next node that needs the bytes fails. In t/27290 and t/191090, the accepted fixes were to stop hand-building the file in a Code node.

Fix, no code: if you have a base64 string in a JSON field, use the Convert to File node, operation Move Base64 String to File. Set Base64 Input Field to your field name, and Put Output File in Field (default data). Under Options you can set File Name and MIME Type.

Fix, in code: let n8n build the object with this.helpers.prepareBinaryData(), and check the input before you use it. Both prepareBinaryData and getBinaryDataBuffer are available in the Code node (runner-types.ts):

const out = [];
for (const item of $input.all()) {
  const b64 = item.json.base64;            // your field name here
  if (!b64) {                              // no content: don't create an empty file
    out.push({ json: { ...item.json, error: 'no file content' } });
    continue;
  }
  const file = await this.helpers.prepareBinaryData(
    Buffer.from(b64, 'base64'), 'invoice.pdf', 'application/pdf');
  out.push({ json: item.json, binary: { data: file } });
}
return out;

To read a file's bytes in a Code node, use await this.helpers.getBinaryDataBuffer(itemIndex, 'data'). n8n's docs say to always use it and avoid reading items[0].binary.data.data directly (n8n: Get the binary data buffer). The reason is in the source: in filesystem, database or S3 mode, data only holds the mode name, such as filesystem-v2, and the real file is behind the id. That's also why a workflow can behave differently on n8n Cloud, a self-hosted server or a pinned test run.

To rename or pass a file through, copy the whole object, not just data: item.binary.image = item.binary.data. Copying only data drops the id. Often you don't need to rename at all: just put the existing field name (for example attachment_0) in the next node's Input Data Field Name.

Cause 2: an empty placeholder file

When some items have a file and some don't, a common workaround is to give the file-less items an empty one, for example item.binary = { data: {} }. That is exactly an object with no id and no data. In t/296649 an AI model node threw this error after a Merge of a "media" branch and a "no media" branch, and the empty-object attempts in that thread only changed which error appeared.

Fix: don't send file-less items to a node that requires a file. Split them with an If or Switch node and give each branch its own path: one node that sends the file, one that doesn't. For Gmail, the accepted answer in t/159868 routed emails with and without attachments to different send nodes, and attached every file with {{ Object.keys($binary).join(',') }}. If you'd rather filter, this Code node keeps only items whose file has real content:

const field = 'data';   // your binary field name
return $input.all().filter(i =>
  i.binary?.[field] && (i.binary[field].id || i.binary[field].data));

Cause 3: the file is on a different item

A node reads the file from its own input item. If the file came from a node further back, or a Merge put it on a separate item, the item being processed doesn't carry it. In t/191090, the accepted answer says you can't reference a binary from a remote node there and uses a Merge node to bring the file to the HTTP Request node. In t/4349, Merge in Append mode produced 45 items without the file and 1 with it, so the node worked once and failed for the rest.

Fix: use Merge with Mode Combine and Combine By Position (or Matching Fields), so the JSON and the file end up on the same item (n8n: Merge). If you need one file on many items, attach it to each item, or loop over the items with the file in each run.

Cause 4: Edit Image produced no output

This is the case in the original t/7550: the poster found that one image in the batch was an SVG while the rest were PNGs. In the current source, the Edit Image node runs the image through GraphicsMagick and passes the result straight to Buffer.from() (EditImage.node.ts). If GraphicsMagick returns no data for a file it can't read, that call fails with this error. We read this from the code and the thread; we didn't test it with an SVG ourselves.

Fix: check the type before the Edit Image node. Add an If node on {{ $binary.data.mimeType }} and send only image/png, image/jpeg and the other types you've tested to Edit Image. Route SVGs (image/svg+xml) and anything else to a different path, for example skip them or convert them with an external service. Turning on Settings → On Error → Continue on Edit Image keeps one bad file from stopping the whole batch.

Cause 5: your own Code node calls Buffer.from() on a missing field

If the stack trace points to your Code node, a line like Buffer.from($json.content, 'base64') got undefined, usually because the field name is different on some items, or an API returned an error object instead of the file. Check before converting, and fail with a message you can read:

const b64 = $json.content;
if (typeof b64 !== 'string' || !b64) {
  throw new Error('No base64 content in "content" for this item: ' + JSON.stringify($json).slice(0, 200));
}
const buf = Buffer.from(b64, 'base64');

A quick way to find the empty file

  1. Open the failed execution and click the node that failed. The error shows the item number, for example [item 2].
  2. Open the node before it, switch the output to the Binary tab, and look at that item. A real file shows a file name, type and size, and you can view or download it.
  3. If that item has no file there, or the file won't open, go back one node at a time until you find where it disappeared. That node is the one to fix, using the cause above that matches it.
  4. If every item looks fine, check the field name: the failing node's Input Data Field Name must match the name shown on the Binary tab (data, attachment_0, a form field name and so on).

FAQ

What does 'The first argument must be of type string or an instance of Buffer ... Received undefined' mean in n8n?
It comes from Node.js Buffer.from() being called with undefined. In n8n it almost always means a node expected a file in a binary field, and the field existed but had no content: no base64 data and no stored file id.

Is this error related to the Buffer social media app?
No. Buffer here is Node.js's type for raw bytes. The error is about binary (file) data inside your workflow, not about the Buffer app or its API.

Why does the HTTP Request node throw this error when uploading a file?
With Form-Data and a parameter of type n8n Binary File, or with the n8n Binary File body type, the node reads the file from the field named in Input Data Field Name. If that field exists but is empty, for example because a Code node built it without data, Buffer.from() gets undefined. Create the file with Convert to File or this.helpers.prepareBinaryData() and make sure it is on the same item.

Why does it work when I pin the previous node but fail on a full run?
Pinned or test data and a live run can carry the file differently. In filesystem, database or S3 mode the binary object holds an id and no real data, so a Code node that reads or copies binary.data.data breaks. Use this.helpers.getBinaryDataBuffer() to read a file and copy the whole binary object to pass it on.

How do I handle items where there is no file?
Don't give them an empty placeholder file. Split items with and without a file using an If or Switch node and send each to its own path, or filter out items whose binary field has neither an id nor data before the node that needs the file.