{"id":"6155b3595a6ca2f4","repo":"drizzle-team/drizzle-orm","slug":"textdecoder-is-not-available-please-provide-eithe-6155b3","errorCode":null,"errorMessage":"TextDecoder is not available. Please provide either Buffer or TextDecoder polyfill.","messagePattern":"TextDecoder is not available\\. Please provide either Buffer or TextDecoder polyfill\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/sql-js/session.ts","lineNumber":208,"sourceCode":"\n\t/** @internal */\n\tisResponseInArrayMode(): boolean {\n\t\treturn this._isResponseInArrayMode;\n\t}\n}\n\nfunction normalizeFieldValue(value: unknown) {\n\tif (value instanceof Uint8Array) { // eslint-disable-line no-instanceof/no-instanceof\n\t\tif (typeof Buffer !== 'undefined') {\n\t\t\tif (!(value instanceof Buffer)) { // eslint-disable-line no-instanceof/no-instanceof\n\t\t\t\treturn Buffer.from(value);\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tif (typeof TextDecoder !== 'undefined') {\n\t\t\treturn new TextDecoder().decode(value);\n\t\t}\n\t\tthrow new Error('TextDecoder is not available. Please provide either Buffer or TextDecoder polyfill.');\n\t}\n\treturn value;\n}\n","sourceCodeStart":190,"sourceCodeEnd":212,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/sql-js/session.ts#L190-L212","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (browser bundle without polyfills)\nimport { drizzle } from 'drizzle-orm/sql-js';\nconst db = drizzle(new Database(data));\nawait db.select().from(files); // files.content is BLOB -> throws\n// after\nimport { Buffer } from 'buffer';\nglobalThis.Buffer = Buffer;\nconst db = drizzle(new Database(data));\nawait db.select().from(files);","handlingStrategy":"validation","validationCode":"function hasBinaryDecoder() {\n  return typeof Buffer !== 'undefined' || typeof TextDecoder !== 'undefined';\n}\nif (!hasBinaryDecoder()) {\n  throw new Error('Provide a Buffer or TextDecoder polyfill before reading BLOB columns with sql.js');\n}","typeGuard":"function binaryDecoderAvailable(): boolean {\n  return typeof Buffer !== 'undefined' || typeof TextDecoder !== 'undefined';\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["sqlite","sql-js","polyfill","environment","binary","blob"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}