denoland/deno · error · NodeError
ERR_METHOD_NOT_IMPLEMENTED
ERR_METHOD_NOT_IMPLEMENTED
Error message
The _write() method is not implemented
What it means
streams.Writable is abstract: the base prototype's _write() throws ERR_METHOD_NOT_IMPLEMENTED unless an _writev exists. The error surfaces on the first chunk the stream tries to flush (delivered to the write callback / 'error' event, destroying the stream), not at construction time.
Source
Thrown at ext/node/polyfills/internal/streams/writable.js:912
} while (i < buffered.length && (state[kState] & kWriting) === 0);
if (i === buffered.length) {
resetBuffer(state);
} else if (i > 256) {
buffered.splice(0, i);
state.bufferedIndex = 0;
} else {
state.bufferedIndex = i;
}
}
state[kState] &= ~kBufferProcessing;
}
Writable.prototype._write = function (chunk, encoding, cb) {
if (this._writev) {
this._writev([{ chunk, encoding }], cb);
} else {
throw new ERR_METHOD_NOT_IMPLEMENTED("_write()");
}
};
Writable.prototype._writev = null;
Writable.prototype.end = function (chunk, encoding, cb) {
const state = this._writableState;
if (typeof chunk === "function") {
cb = chunk;
chunk = null;
encoding = null;
} else if (typeof encoding === "function") {
cb = encoding;
encoding = null;
}
let err;View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Pass the implementation in options: new Writable({ write(chunk, enc, cb) { /* store */ cb(); } })
- Implement _write(chunk, enc, cb) (or _writev) on the subclass prototype
- Use a concrete stream (fs.createWriteStream, net.Socket) when you only need output
Example fix
// before
class Sink extends Writable {}
new Sink().end('x'); // ERR_METHOD_NOT_IMPLEMENTED on flush
// after
class Sink extends Writable {
_write(chunk, _enc, cb) { process.stdout.write(chunk, cb); }
}
new Sink().end('x'); // ok Defensive patterns
Strategy: validation
Validate before calling
function makeWritable(writeImpl) {
if (typeof writeImpl !== 'function') {
throw new Error('Writable requires a write(chunk, enc, cb) implementation');
}
return new Writable({ write: writeImpl });
} Type guard
const hasWriteImpl = (s) => typeof s._write === 'function' && (s._write !== Writable.prototype._write || typeof s._writev === 'function');
Try / catch
ws.on('error', (err) => {
if (err.code === 'ERR_METHOD_NOT_IMPLEMENTED') {
console.error('Implement _write(chunk, enc, cb) on this Writable subclass');
}
}); Prevention
- Always pass write() in constructor options or implement _write/_writev
- Name the method exactly _write (leading underscore included)
- Smoke-test custom streams with a single write() before wiring pipelines
When it happens
Trigger: new Writable({highWaterMark: 16}) with no write option, followed by .write()/end(); class MyOut extends Writable {} that adds a constructor but never defines _write/_writev; a method misnamed write() or _write2 instead of _write.
Common situations: Porting stream samples; refactors that rename or drop _write; test fakes/mocks of Writable without a write implementation.
Related errors
- ERR_STREAM_NULL_VALUES
- ERR_INVALID_ARG_TYPE
- ERR_METHOD_NOT_IMPLEMENTED
- ERR_INVALID_ARG_TYPE
- ERR_CONSOLE_WRITABLE_STREAM
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/ccf8379753e13701.
Report an issue: GitHub.