winstonjs/winston · error · Error
options.stream is required.
Error message
options.stream is required.
What it means
The Stream transport wraps a caller-provided writable stream. The constructor throws this Error when options.stream is missing or is not recognized as a stream (checked with the is-stream helper). Unlike File, Stream has no fallback destination, so a valid stream is mandatory.
Source
Thrown at lib/winston/transports/stream.js:30
const os = require('os');
const TransportStream = require('winston-transport');
/**
* Transport for outputting to any arbitrary stream.
* @type {Stream}
* @extends {TransportStream}
*/
module.exports = class Stream extends TransportStream {
/**
* Constructor function for the Console transport object responsible for
* persisting log messages and metadata to a terminal or TTY.
* @param {!Object} [options={}] - Options for this instance.
*/
constructor(options = {}) {
super(options);
if (!options.stream || !isStream(options.stream)) {
throw new Error('options.stream is required.');
}
// We need to listen for drain events when write() returns false. This can
// make node mad at times.
this._stream = options.stream;
this._stream.setMaxListeners(Infinity);
this.isObjectMode = options.stream._writableState.objectMode;
this.eol = (typeof options.eol === 'string') ? options.eol : os.EOL;
}
/**
* Core logging method exposed to Winston.
* @param {Object} info - TODO: add param description.
* @param {Function} callback - TODO: add param description.
* @returns {undefined}
*/
log(info, callback) {
setImmediate(() => this.emit('logged', info));View on GitHub (pinned to ff0b79de85)
Solutions
- Pass an actual writable stream: new winston.transports.Stream({ stream: process.stdout }).
- If you meant to log to a file by path, use winston.transports.File({ filename }) instead of Stream.
- Verify the value passes a stream check (isStream / stream.writable) before constructing.
Example fix
// before
new winston.transports.Stream({ stream: '/var/log/app.log' }); // string, not a stream
// after
new winston.transports.File({ filename: '/var/log/app.log' });
// or
new winston.transports.Stream({ stream: process.stdout }); Defensive patterns
Strategy: type-guard
Validate before calling
function requireWritableStream(s) {
if (!s || typeof s.write !== 'function') {
throw new TypeError('Stream transport requires a writable Node stream');
}
return s;
}
// new winston.transports.Stream({ stream: requireWritableStream(process.stdout) }); Type guard
const isWritableStream = (s) => !!s && typeof s.write === 'function' && typeof s.on === 'function';
Try / catch
try {
streamTransport = new winston.transports.Stream({ stream: target });
} catch (err) {
if (err.message === 'options.stream is required.') {
console.error('Expected a writable stream, got:', typeof target);
}
throw err;
} Prevention
- Remember Stream takes a stream object, not a path — use File for paths.
- Check the candidate with a writable-stream type guard before constructing.
- For process.stdout/stderr, pass the stream object itself inside { stream: ... }.
When it happens
Trigger: new winston.transports.Stream({}) ; new winston.transports.Stream({ stream: someString }) ; passing a duplex-less value such as a plain object, a file path string, or an http.IncomingMessage (readable) where a writable stream is required.
Common situations: Passing a filename string expecting Stream to open it (use File transport instead); passing process.stdout without options wrapping (must be options.stream = process.stdout); passing a readline interface or socket that isStream does not recognize.
Understand the failure class
Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.
Related errors
- Cannot make set from type other than Array of string element
- Cannot log to file without filename or stream.
- { %s } was removed in winston@3.0.0.
- { %s } was removed in winston@3.0.0. Use a custom winston.fo
- Logger is required to handle exceptions
AI-assisted analysis of winstonjs/winston@ff0b79de85 (2026-08-31).
Data as JSON: /api/errors/6c8030d4e421fc7d.
Report an issue: GitHub.