How to fix TypeError: list argument must be an Array of Buffer instances in Node.js

Node.jsBEGINNERMEDIUMUpdated Dec 22, 2025ยท 145 views

This error occurs when Buffer.concat() receives arguments that are not Buffer or Uint8Array instances. The method expects an array containing only Buffer or Uint8Array objects, but receives strings, plain objects, or other incompatible types instead.

Quick fix

Fixes ERR_INVALID_ARG_TYPE

// Check what you're trying to concatenate
console.log('Data types:', chunks.map(c => typeof c));
console.log('Is Buffer:', chunks.map(c => Buffer.isBuffer(c)));
console.log('Actual values:', chunks);

const result = Buffer.concat(chunks);
  1. Inspect the data being passed to Buffer.concat()
  2. Validate all elements are Buffers before concatenating
  3. Fix the source of non-Buffer data
  4. Handle edge cases with proper initialization
node.js โ€” error
// Check what you're trying to concatenate
console.log('Data types:', chunks.map(c => typeof c));
console.log('Is Buffer:', chunks.map(c => Buffer.isBuffer(c)));
console.log('Actual values:', chunks);
const result = Buffer.concat(chunks);
TypeError: list argument must be an Array of Buffer instances

What this error means

Buffer.concat() is a Node.js method that combines multiple Buffer instances into a single Buffer. This error is thrown when the method validates its arguments and discovers that the provided list contains elements that are not Buffer or Uint8Array instances. The error can manifest in several ways depending on the Node.js version. Modern versions may show "ERR_INVALID_ARG_TYPE: The 'list[0]' argument must be one of type Array, Buffer, or Uint8Array. Received type string" while older versions show the simpler "list argument must be an Array of Buffer instances". This typically happens in data processing pipelines where mixed data types accumulate, in stream handling code where chunks are improperly managed, or when working with APIs that return data in unexpected formats.

Typical symptoms

  • Buffer.concat() throws TypeError when attempting to concatenate data
  • Error message specifies "list argument must be an Array of Buffer instances"
  • Modern Node.js versions show ERR_INVALID_ARG_TYPE with specific index
  • Error occurs during file operations, network stream processing, or binary data handling
  • Code works with some inputs but fails with others
  • buf.copy is not a function error in older implementations

Common causes

  1. Passing strings instead of Buffers to Buffer.concat()
  2. Accidentally including undefined or null values in the Buffer array
  3. Mixing Buffer instances with plain JavaScript objects or arrays
  4. Converting data improperly before concatenation (e.g., JSON.stringify results)
  5. Stream handlers accumulating non-Buffer data types
  6. Exceeding maxHttpBufferSize causing empty strings to replace Buffers
  7. Using incompatible TypedArray types that are not Uint8Array-based
  8. Not validating data types before adding to concatenation array

How to fix "TypeError: list argument must be an Array of Buffer instances"

1Inspect the data being passed to Buffer.concat()

Add debugging before the Buffer.concat() call to see what types you're actually passing:

javascript
// Check what you're trying to concatenate
console.log('Data types:', chunks.map(c => typeof c));
console.log('Is Buffer:', chunks.map(c => Buffer.isBuffer(c)));
console.log('Actual values:', chunks);

const result = Buffer.concat(chunks);

This will reveal if strings, objects, or other non-Buffer types have entered your array.

2Validate all elements are Buffers before concatenating

Add validation to ensure all elements are Buffer or Uint8Array instances:

javascript
// Filter out invalid elements and convert if possible
const validChunks = chunks
  .filter(chunk => chunk != null) // Remove null/undefined
  .map(chunk => {
    if (Buffer.isBuffer(chunk)) {
      return chunk;
    }
    if (typeof chunk === 'string') {
      return Buffer.from(chunk); // Convert strings to Buffer
    }
    if (chunk instanceof Uint8Array) {
      return Buffer.from(chunk); // Convert Uint8Array to Buffer
    }
    console.warn('Skipping invalid chunk:', typeof chunk);
    return null;
  })
  .filter(chunk => chunk !== null);

const result = Buffer.concat(validChunks);

This ensures only valid Buffer instances are concatenated.

3Fix the source of non-Buffer data

Identify where non-Buffer data is being added to your array. Common scenarios:

Stream handling:

javascript
// BAD - mixing strings and Buffers
stream.on('data', (chunk) => {
  if (someCondition) {
    chunks.push(chunk.toString()); // String!
  } else {
    chunks.push(chunk); // Buffer
  }
});

// GOOD - keep everything as Buffer
stream.on('data', (chunk) => {
  chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
});

API responses:

javascript
// BAD - JSON stringified data
const data = JSON.stringify(obj);
chunks.push(data); // String, not Buffer

// GOOD - convert to Buffer explicitly
const data = JSON.stringify(obj);
chunks.push(Buffer.from(data, 'utf8'));
4Handle edge cases with proper initialization

Ensure your chunks array is properly initialized and managed:

javascript
let chunks = []; // Start with empty array

// Always validate before adding
function addChunk(data) {
  if (data == null) return; // Skip null/undefined

  const chunk = Buffer.isBuffer(data)
    ? data
    : Buffer.from(data);

  chunks.push(chunk);
}

// Safe concatenation with empty check
function getResult() {
  if (chunks.length === 0) {
    return Buffer.alloc(0); // Return empty Buffer
  }
  return Buffer.concat(chunks);
}

This prevents accumulating invalid data types throughout your processing pipeline.

5Use Buffer.isBuffer() for runtime validation

Add defensive checks especially when handling external data:

javascript
function safeConcatBuffers(bufferList) {
  if (!Array.isArray(bufferList)) {
    throw new TypeError('Expected an array of Buffers');
  }

  // Validate all elements
  const invalidIndex = bufferList.findIndex(
    item => !Buffer.isBuffer(item) && !(item instanceof Uint8Array)
  );

  if (invalidIndex !== -1) {
    throw new TypeError(
      `Element at index ${invalidIndex} is not a Buffer or Uint8Array. ` +
      `Got: ${typeof bufferList[invalidIndex]}`
    );
  }

  return Buffer.concat(bufferList);
}

// Usage
try {
  const result = safeConcatBuffers(chunks);
} catch (err) {
  console.error('Buffer concatenation failed:', err.message);
}

Advanced notes

Buffer and Uint8Array Compatibility:
Node.js Buffer extends Uint8Array, so Buffer instances are valid where Uint8Array is expected. However, not all TypedArray types work with Buffer.concat() - only Uint8Array and its subclasses (including Buffer) are accepted.

Performance Considerations:
If you're concatenating many small Buffers in a loop, consider pre-calculating the total length and passing it as the second argument to Buffer.concat(totalLength). This avoids recalculating the length internally and improves performance.

Stream Best Practices:
When collecting Buffer chunks from streams, always maintain type consistency. If you need to process the data as strings temporarily, convert back to Buffer before concatenation rather than mixing types.

HTTP Buffer Size Limits:
In HTTP servers, exceeding maxHttpBufferSize can cause frameworks to substitute empty strings for Buffers. Configure appropriate limits and handle overflow scenarios explicitly rather than allowing silent type changes.

TypeScript Users:
Use proper typing to catch these errors at compile time:

typescript
const chunks: Buffer[] = [];
// TypeScript will catch attempts to add non-Buffer types

Frequently asked questions

What does "ERR_INVALID_ARG_TYPE" mean?
js method that combines multiple Buffer instances into a single Buffer. This error is thrown when the method validates its arguments and discovers that the provided list contains elements that are not Buffer or Uint8Array instances. js version.
How do I fix "ERR_INVALID_ARG_TYPE"?
This error occurs when Buffer.concat() receives arguments that are not Buffer or Uint8Array instances. The method expects an array containing only Buffer or Uint8Array objects, but receives strings, plain objects, or other incompatible types instead.
What causes "ERR_INVALID_ARG_TYPE"?
Passing strings instead of Buffers to Buffer.concat() Accidentally including undefined or null values in the Buffer array Mixing Buffer instances with plain JavaScript objects or arrays
Is the "ERR_INVALID_ARG_TYPE" error serious?
It is a medium-severity error โ€” more of a blocker than a risk. The steps above resolve it.

Official resources & further reading