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
- Pass a transport instance: `new winston.RejectionStream(new winston.transports.File({ filename: 'rejections.log' }))`.
- Create the transport before constructing the stream.
- Prefer `logger.rejections.handle(transport)` so winston constructs the stream for you.
- 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
- Prefer `logger.rejections.handle(transport)` over manual RejectionStream usage
- Construct transports before streams that wrap them
- Do not pass a Logger where a TransportStream is required
- Validate transport arguments in wrapper libraries
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
- ExceptionStream requires a TransportStream instance.
- Transports must WritableStreams in objectMode. Set { objectM
- Logger is required to handle rejections
- Logger is required to handle exceptions
- Logger is required for profiling
AI-assisted analysis of winstonjs/winston@ff0b79de85 (2026-08-31).
Data as JSON: /api/errors/c8e1cde158191723.
Report an issue: GitHub.