{"record":{"id":"6c8030d4e421fc7d","repo":"winstonjs/winston","slug":"options-stream-is-required","errorCode":null,"errorMessage":"options.stream is required.","messagePattern":"options\\.stream is required\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/winston/transports/stream.js","lineNumber":30,"sourceCode":"const os = require('os');\nconst TransportStream = require('winston-transport');\n\n/**\n * Transport for outputting to any arbitrary stream.\n * @type {Stream}\n * @extends {TransportStream}\n */\nmodule.exports = class Stream extends TransportStream {\n  /**\n   * Constructor function for the Console transport object responsible for\n   * persisting log messages and metadata to a terminal or TTY.\n   * @param {!Object} [options={}] - Options for this instance.\n   */\n  constructor(options = {}) {\n    super(options);\n\n    if (!options.stream || !isStream(options.stream)) {\n      throw new Error('options.stream is required.');\n    }\n\n    // We need to listen for drain events when write() returns false. This can\n    // make node mad at times.\n    this._stream = options.stream;\n    this._stream.setMaxListeners(Infinity);\n    this.isObjectMode = options.stream._writableState.objectMode;\n    this.eol = (typeof options.eol === 'string') ? options.eol : os.EOL;\n  }\n\n  /**\n   * Core logging method exposed to Winston.\n   * @param {Object} info - TODO: add param description.\n   * @param {Function} callback - TODO: add param description.\n   * @returns {undefined}\n   */\n  log(info, callback) {\n    setImmediate(() => this.emit('logged', info));","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/winstonjs/winston/blob/ff0b79de8562bb322c390fbc82fe71c11f373428/lib/winston/transports/stream.js#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nnew winston.transports.Stream({ stream: '/var/log/app.log' }); // string, not a stream\n// after\nnew winston.transports.File({ filename: '/var/log/app.log' });\n// or\nnew winston.transports.Stream({ stream: process.stdout });","handlingStrategy":"type-guard","validationCode":"function requireWritableStream(s) {\n  if (!s || typeof s.write !== 'function') {\n    throw new TypeError('Stream transport requires a writable Node stream');\n  }\n  return s;\n}\n// new winston.transports.Stream({ stream: requireWritableStream(process.stdout) });","typeGuard":"const isWritableStream = (s) => !!s && typeof s.write === 'function' && typeof s.on === 'function';","tryCatchPattern":"try {\n  streamTransport = new winston.transports.Stream({ stream: target });\n} catch (err) {\n  if (err.message === 'options.stream is required.') {\n    console.error('Expected a writable stream, got:', typeof target);\n  }\n  throw err;\n}","preventionTips":["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: ... }."],"tags":["winston","stream-transport","missing-option","type-error"],"backgroundTag":"missing-required-option","analyzedSha":"ff0b79de8562bb322c390fbc82fe71c11f373428","analyzedAt":"2026-08-31T13:33:44.585Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}