denoland/deno · error · RangeError

${prefix}: WritableStream does not support 'type' in the und

Error message

${prefix}: WritableStream does not support 'type' in the underlying sink

What it means

RangeError thrown by the WritableStream constructor when the converted underlyingSink dictionary has a non-null `type` member (ext/web/06_streams.js). Deno implements value-mode writable streams only; 'bytes' (writable byte streams) and any other type value are unsupported, so the constructor refuses the sink at creation time.

Source

Thrown at ext/web/06_streams.js:7402

    }
    strategy = strategy !== undefined
      ? webidl.converters.QueuingStrategy(
        strategy,
        prefix,
        "Argument 2",
      )
      : {};
    this[_brand] = _brand;
    if (underlyingSink === undefined) {
      underlyingSink = null;
    }
    const underlyingSinkDict = webidl.converters.UnderlyingSink(
      underlyingSink,
      prefix,
      "underlyingSink",
    );
    if (underlyingSinkDict.type != null) {
      throw new RangeError(
        `${prefix}: WritableStream does not support 'type' in the underlying sink`,
      );
    }
    initializeWritableStream(this);
    const sizeAlgorithm = extractSizeAlgorithm(strategy);
    const highWaterMark = extractHighWaterMark(strategy, 1);
    setUpWritableStreamDefaultControllerFromUnderlyingSink(
      this,
      underlyingSink,
      underlyingSinkDict,
      highWaterMark,
      sizeAlgorithm,
    );
  }

  /** @returns {boolean} */
  get locked() {
    webidl.assertBranded(this, WritableStreamPrototype);

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Remove the `type` property from the underlyingSink object; write Uint8Array chunks through a default WritableStream instead.
  2. If byte-level control is needed, wrap a WritableStream around a File/FsFile or socket sink and accept ArrayBufferView chunks.
  3. Check feature support before passing type: only include it when the runtime advertises writable byte streams.

Example fix

// before
const ws = new WritableStream({
  type: 'bytes', // RangeError in Deno
  write(chunk, ctrl) { file.write(chunk); },
});

// after
const ws = new WritableStream({
  write(chunk, ctrl) { file.write(chunk); }, // value mode; chunk: Uint8Array
});
Defensive patterns

Strategy: validation

Validate before calling

// Only pass `type` when the runtime supports writable byte streams;
// Deno does not. Strip it before constructing.
function makeWritable(sink) {
  const { type, ...rest } = sink; // eslint-disable-line no-unused-vars
  return new WritableStream(rest); // value-mode sink
}

Try / catch

try {
  ws = new WritableStream(sink); // sink may carry type: 'bytes'
} catch (err) {
  if (err instanceof RangeError && /does not support 'type'/.test(err.message)) {
    const { type, ...sink } = rawSink;
    ws = new WritableStream(sink);
  } else throw err;
}

Prevention

When it happens

Trigger: new WritableStream({ type: 'bytes', write(chunk, controller) {...} }); any non-null type such as 'direct'. Commonly triggered by libraries or spec-draft-derived code that request byte-oriented sinks.

Common situations: Porting browser/experimental code that relies on writable byte streams (SPECULATION feature); npm packages probing for capability by constructing a typed sink; copy-paste from WHATWG Streams proposals.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/78d854a744be63b2. Report an issue: GitHub.