ERR_STREAM_READ_NOT_IMPLEMENTED
Node.jsERRORNotableStreamHIGH confidence

Readable stream subclass did not implement _read()

Production Risk

Causes stream to error on first read; easy to catch in development.

What this means

Thrown when a class extends stream.Readable but does not implement the required _read() method. The _read() method is the hook that custom Readable streams must override to supply data to consumers.

Why it happens
  1. 1Subclassing Readable without overriding _read()
  2. 2Forgetting to implement _read() when converting a class to a Readable
  3. 3Typo in the method name (e.g. read() instead of _read())
How to reproduce

Triggered when the stream infrastructure calls _read() and finds only the base-class no-op that throws.

trigger — this will error
trigger — this will error
const { Readable } = require('stream');
class MyStream extends Readable {
  // _read() not implemented
}
const s = new MyStream();
s.on('data', console.log); // triggers _read(), which throws

expected output

Error [ERR_STREAM_READ_NOT_IMPLEMENTED]: _read() is not implemented

Fix 1

Implement _read() in your Readable subclass

WHEN Always — required when subclassing Readable

Implement _read() in your Readable subclass
class MyStream extends Readable {
  constructor() {
    super();
    this._data = ['a', 'b', 'c', null];
    this._index = 0;
  }
  _read() {
    this.push(this._data[this._index++]);
  }
}

Why this works

_read() is the producer hook; implementing it correctly supplies data to the stream buffer.

Fix 2

Use Readable.from() for simple iterables instead of subclassing

WHEN When the data source is an iterable or async iterable

Use Readable.from() for simple iterables instead of subclassing
const { Readable } = require('stream');
const stream = Readable.from(['a', 'b', 'c']);

Why this works

Readable.from() wraps an iterable in a Readable without requiring _read() implementation.

Code examples
Triggerjs
const { Readable } = require('stream');
class MyStream extends Readable {
  // _read() not implemented
}
const s = new MyStream();
s.on('data', console.log); // triggers _read(), which throws  // this triggers ERR_STREAM_READ_NOT_IMPLEMENTED
Handle in try/catchjs
try {
  // operation that may throw ERR_STREAM_READ_NOT_IMPLEMENTED
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_STREAM_READ_NOT_IMPLEMENTED') {
    console.error('ERR_STREAM_READ_NOT_IMPLEMENTED:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_stream_read_not_implemented(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Subclass Readable without implementing _read()

_read() is abstract; the base class implementation explicitly throws this error.

Same error in other languages
Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors