winstonjs/winston · error · Error

RejectionStream requires a TransportStream instance.

Error message

RejectionStream requires a TransportStream instance.

What it means

RejectionStream mirrors ExceptionStream: an objectMode stream that filters unhandled-rejection entries to a given TransportStream. Its constructor throws immediately when no transport is supplied, because the stream would have nowhere to send rejection records.

Source

Thrown at lib/winston/rejection-stream.js:28

const { Writable } = require('readable-stream');

/**
 * TODO: add class description.
 * @type {RejectionStream}
 * @extends {Writable}
 */
module.exports = class RejectionStream extends Writable {
  /**
   * Constructor function for the RejectionStream responsible for wrapping a
   * TransportStream; only allowing writes of `info` objects with
   * `info.rejection` set to true.
   * @param {!TransportStream} transport - Stream to filter to rejections
   */
  constructor(transport) {
    super({ objectMode: true });

    if (!transport) {
      throw new Error('RejectionStream requires a TransportStream instance.');
    }

    this.handleRejections = true;
    this.transport = transport;
  }

  /**
   * Writes the info object to our transport instance if (and only if) the
   * `rejection` property is set on the info.
   * @param {mixed} info - TODO: add param description.
   * @param {mixed} enc - TODO: add param description.
   * @param {mixed} callback - TODO: add param description.
   * @returns {mixed} - TODO: add return description.
   * @private
   */
  _write(info, enc, callback) {
    if (info.rejection) {
      return this.transport.log(info, callback);

View on GitHub (pinned to ff0b79de85)

Solutions

  1. Pass a transport instance: `new winston.RejectionStream(new winston.transports.File({ filename: 'rejections.log' }))`.
  2. Create the transport before constructing the stream.
  3. Prefer `logger.rejections.handle(transport)` so winston constructs the stream for you.
  4. Assert the argument is a transport before constructing.

Example fix

// before
const stream = new winston.RejectionStream();

// after
const stream = new winston.RejectionStream(
  new winston.transports.File({ filename: 'rejections.log' })
);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!transport || typeof transport.log !== 'function') {
  throw new TypeError('RejectionStream needs a TransportStream; got: ' + String(transport));
}

Type guard

function isTransportStream(x) { return !!x && typeof x.log === 'function' && !!x._writableState && x._writableState.objectMode; }

Try / catch

let stream;
try {
  stream = new winston.RejectionStream(transport);
} catch (err) {
  if (err.message.startsWith('RejectionStream requires')) {
    stream = new winston.RejectionStream(new winston.transports.File({ filename: 'rejections.log' }));
  } else { throw err; }
}

Prevention

When it happens

Trigger: Calling `new winston.RejectionStream()` with no argument or falsy value; passing a non-transport (plain object, logger, raw stream) in custom unhandledRejection routing.

Common situations: Custom rejection pipelines where the transport wasn't initialized yet; confusing Logger with TransportStream arguments; hand-rolled rejection handling in libraries built on winston.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of winstonjs/winston@ff0b79de85 (2026-08-31). Data as JSON: /api/errors/c8e1cde158191723. Report an issue: GitHub.