clockworklabs/SpacetimeDB · error · TypeError
Option 'stream' not supported
Error message
Option 'stream' not supported
What it means
The builtin TextDecoder only supports one-shot decoding: decode(input) with no options. Passing `{ stream: true }` — the WHATWG mechanism for feeding chunks incrementally while carrying partial code points across calls — throws a TypeError, because stateful/incremental decoding is not implemented in the module host.
Solutions
- Accumulate Uint8Array chunks in a buffer and call decode() once on the complete payload
- Split on byte boundaries (e.g. newline bytes) manually, then decode each complete slice without options
- Keep incremental text parsing on the client side rather than inside the module
Example fix
// before
let text = '';
for (const chunk of chunks) {
text += dec.decode(chunk, { stream: true }); // TypeError in module
}
// after
const parts: Uint8Array[] = [];
for (const chunk of chunks) parts.push(chunk);
const text = dec.decode(concatBytes(parts)); // one-shot, no options Defensive patterns
Strategy: fallback
Validate before calling
function decodeSafe(dec: TextDecoder, bytes: Uint8Array, opts: { stream?: boolean } = {}): string {
// fallback: the module builtin has no streaming mode; buffer and decode once
if (opts.stream) buffer.push(bytes); // caller flushes later with decodeSafe(dec, flush(), {})
return opts.stream ? '' : dec.decode(concatBytes(buffer.splice(0)));
} Try / catch
try {
text = dec.decode(chunk, { stream: true });
} catch (e) {
if (e instanceof TypeError) {
pending.push(chunk); // fall back to buffering
text = '';
}
} Prevention
- Design module parsers around complete byte buffers, not streaming decode
- Split streams on byte delimiters before decoding
- Keep incremental text pipelines on the client side
When it happens
Trigger: decoder.decode(chunk, { stream: true }) inside incremental parsers ported into a SpacetimeDB V8 module: NDJSON/CSV readers, ReadableStream pipelines, and any loop that decodes byte chunks as they arrive.
Common situations: Porting Node stream-processing code into a module; libraries like ndjson parsers that depend on streaming TextDecoder semantics.
Related errors
- Option 'ignoreBOM' not supported
- The encoding label provided is invalid
- Math.random is not available in SpacetimeDB modules. Use…
- must export schema as default export
- all-zeroes commit header
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/fa559caf1fd8609e.
Report an issue: GitHub.
Appendix: source
Thrown at crates/core/src/host/v8/builtins/text_encoding.js:57
}
get encoding() {
return this.#encoding;
}
get fatal() {
return this.#fatal;
}
get ignoreBOM() {
return false;
}
/**
* @argument {any} input
* @argument {any} options
*/
decode(input, options = {}) {
if (options.stream) {
throw new TypeError("Option 'stream' not supported");
}
if (input instanceof ArrayBuffer || input instanceof SharedArrayBuffer) {
input = new Uint8Array(input);
}
return utf8_decode(input, this.#fatal);
}
};
View on GitHub (pinned to 6dee26c6ef)