drizzle-team/drizzle-orm · error · Error
TextDecoder is not available. Please provide either Buffer o
Error message
TextDecoder is not available. Please provide either Buffer or TextDecoder polyfill.
What it means
Thrown by normalizeFieldValue (sql-js/session.ts:208) when a SQLite cell comes back as a Uint8Array (BLOB) but the runtime has neither Node's Buffer nor a global TextDecoder. sql.js returns binary columns as Uint8Array, and Drizzle needs one of those globals to convert the bytes into a usable value, so it errors asking for a polyfill.
Source
Thrown at drizzle-orm/src/sql-js/session.ts:208
/** @internal */
isResponseInArrayMode(): boolean {
return this._isResponseInArrayMode;
}
}
function normalizeFieldValue(value: unknown) {
if (value instanceof Uint8Array) { // eslint-disable-line no-instanceof/no-instanceof
if (typeof Buffer !== 'undefined') {
if (!(value instanceof Buffer)) { // eslint-disable-line no-instanceof/no-instanceof
return Buffer.from(value);
}
return value;
}
if (typeof TextDecoder !== 'undefined') {
return new TextDecoder().decode(value);
}
throw new Error('TextDecoder is not available. Please provide either Buffer or TextDecoder polyfill.');
}
return value;
}
View on GitHub (pinned to b7862528fd)
Solutions
- Provide a Buffer polyfill (e.g. `buffer` package) in the bundle for browser/edge.
- Ensure the global TextDecoder is available (e.g. `util.TextDecoder` polyfill via node util in older runtimes).
- Avoid selecting BLOB columns in environments that cannot satisfy either polyfill.
Example fix
// before (browser bundle without polyfills)
import { drizzle } from 'drizzle-orm/sql-js';
const db = drizzle(new Database(data));
await db.select().from(files); // files.content is BLOB -> throws
// after
import { Buffer } from 'buffer';
globalThis.Buffer = Buffer;
const db = drizzle(new Database(data));
await db.select().from(files); Defensive patterns
Strategy: validation
Validate before calling
function hasBinaryDecoder() {
return typeof Buffer !== 'undefined' || typeof TextDecoder !== 'undefined';
}
if (!hasBinaryDecoder()) {
throw new Error('Provide a Buffer or TextDecoder polyfill before reading BLOB columns with sql.js');
} Type guard
function binaryDecoderAvailable(): boolean {
return typeof Buffer !== 'undefined' || typeof TextDecoder !== 'undefined';
} Prevention
- Bundle the `buffer` package (set globalThis.Buffer) in browser/edge for sql.js.
- Ensure global TextDecoder is present (util.TextDecoder polyfill) in minimal runtimes.
- Avoid selecting BLOB columns where no binary decoder is available.
When it happens
Trigger: Running sql.js (drizzle-orm/sql-js) in a restricted runtime (some edge workers, legacy bundlers, minimal sandboxes) that lacks both Buffer and TextDecoder while reading a BLOB/binary column.
Common situations: Bundling sql.js for the browser without a Buffer polyfill; running in a minimal JS engine without Web APIs; tree-shaking or polyfill config dropping TextDecoder; reading BLOB columns in environments configured for text-only.
Related errors
- TextDecoder is not available. Please provide either Buffer o
- Method not implemented.
- Failed query: ${queryString} params: ${params}
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/6155b3595a6ca2f4.json.
Report an issue: GitHub.