{"id":"9860629a1ca2a5d8","repo":"drizzle-team/drizzle-orm","slug":"textdecoder-is-not-available-please-provide-eithe","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":"critical","filePath":"drizzle-orm/src/libsql/session.ts","lineNumber":324,"sourceCode":"\t\tif (Object.prototype.propertyIsEnumerable.call(obj, key)) {\n\t\t\tacc[key] = obj[key];\n\t\t}\n\t\treturn acc;\n\t}, {});\n}\n\nfunction normalizeFieldValue(value: unknown) {\n\tif (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) { // 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":306,"sourceCodeEnd":328,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/libsql/session.ts#L306-L328","documentation":"Thrown by normalizeFieldValue in the LibSQL session (line 324) when a returned value is an ArrayBuffer but neither Buffer (Node) nor TextDecoder (browser/modern runtimes) is available to decode it. This is purely an environment capability gap - the runtime lacks the global APIs Drizzle needs to materialize binary column data.","triggerScenarios":"A LibSQL query returns a binary/blob column whose value arrives as ArrayBuffer, and the JS runtime exposes neither global Buffer nor global TextDecoder. Common in stripped-down or non-standard runtimes.","commonSituations":"Running Drizzle + LibSQL on an edge runtime or custom embedded JS engine that lacks TextDecoder; bundling with aggressive polyfill stripping that removes Node Buffer; older environments without TextDecoder support.","solutions":["Add a TextDecoder polyfill to your runtime/bundle (e.g. fast-text-encoding) so globalThis.TextDecoder is defined.","If on Node, ensure Buffer is available - avoid bundlers that strip node:buffer.","Run on a runtime that ships TextDecoder natively (modern browsers, Node 18+, Cloudflare Workers, Deno).","Avoid selecting BLOB columns if you cannot provide a decoder, or cast them to text in SQL."],"exampleFix":"// before - runtime lacks TextDecoder\n// Error: TextDecoder is not available...\n\n// after - install a polyfill before any query\nimport 'fast-text-encoding'; // adds global TextDecoder\n// or in entry:\nglobalThis.TextDecoder = globalThis.TextDecoder || (await import('util')).TextDecoder;\nawait db.select().from(files).where(eq(files.id, id));","handlingStrategy":"validation","validationCode":"// Ensure a decoder exists before running queries\nconst hasDecoder = typeof Buffer !== 'undefined' || typeof TextDecoder !== 'undefined';\nif (!hasDecoder) {\n  throw new Error('Install a TextDecoder polyfill (e.g. fast-text-encoding).');\n}","typeGuard":"function hasBinaryDecoder(): boolean {\n  return typeof Buffer !== 'undefined' || typeof TextDecoder !== 'undefined';\n}","tryCatchPattern":null,"preventionTips":["Run on a runtime with TextDecoder (Node 18+, modern browsers, Deno, CF Workers).","Polyfill TextDecoder in stripped runtimes before importing drizzle-orm.","Avoid bundler settings that strip node:buffer.","Cast BLOB columns to text in SQL if you can't decode binary."],"tags":["libsql","sqlite","environment","polyfill","runtime","binary"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}