ERR_STREAM_NULL_VALUES
Node.jsERRORNotableStreamHIGH confidence

Non-object-mode stream received null value

Production Risk

Low — caught immediately at call site; fix by using end() or object mode.

What this means

Thrown when null is passed to a Readable or Writable stream write/push in a non-object-mode stream in a context where null is not the intended EOF signal, or when the stream implementation misuses null. In Readable streams, push(null) is valid as EOF; but write(null) on a Writable is always invalid.

Why it happens
  1. 1Calling writable.write(null) on a non-object-mode stream
  2. 2Passing null as a chunk to a Transform stream
  3. 3Misunderstanding that null is the EOF signal for push(), not write()
How to reproduce

Triggered when write() or push() receives null in a context where it is not treated as EOF.

trigger — this will error
trigger — this will error
const { Writable } = require('stream');
const w = new Writable({
  write(chunk, enc, cb) { cb(); }
});
w.write(null); // throws — null is not a valid write() argument

expected output

Error [ERR_STREAM_NULL_VALUES]: May not write null values to stream

Fix 1

Use end() instead of write(null) to finish a Writable

WHEN When signalling end of data to a Writable

Use end() instead of write(null) to finish a Writable
w.write(Buffer.from('last chunk'));
w.end(); // correct way to end a Writable

Why this works

end() properly signals completion; write(null) is never valid for Writables.

Fix 2

Enable objectMode if you need to pass null as a value

WHEN When your stream legitimately handles null as a data value

Enable objectMode if you need to pass null as a value
const w = new Writable({
  objectMode: true,
  write(obj, enc, cb) { console.log(obj); cb(); }
});
w.write(null); // valid in objectMode

Why this works

In object mode, null written via write() is allowed as a plain object value.

Code examples
Triggerjs
const { Writable } = require('stream');
const w = new Writable({
  write(chunk, enc, cb) { cb(); }
});
w.write(null); // throws — null is not a valid write() argument  // this triggers ERR_STREAM_NULL_VALUES
Handle in try/catchjs
try {
  // operation that may throw ERR_STREAM_NULL_VALUES
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_STREAM_NULL_VALUES') {
    console.error('ERR_STREAM_NULL_VALUES:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_stream_null_values(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Pass null to write() on a byte/string stream

null is reserved as the EOF signal for push(); write(null) is always invalid.

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