#5771 D1 via miniflare doesn't accept Buffer for blobs
Assertion fails for Buffer (extends Uint8Array) in devalue.ts. Uint8Array works.
Fix devalue handler to accept Buffer type
Analysis Report
Issue Review: cloudflare/workers-sdk#5771
Summary
D1 via Miniflare doesn't accept Buffer type for blob columns - throws assertion error.
Findings
- Created: 2024-05-07
- Updated: 2025-10-30
- Version: wrangler 3.53.1 → 4.61.0
- Component: miniflare, d1
- Labels: bug, miniflare
- Comments: 0
Key Evidence
- Passing Buffer to D1 blob column in local dev throws assertion error in devalue handler
- Passing Uint8Array works fine
- Root cause: Miniflare's devalue.ts has assertion that fails for Buffer (which is a subclass of Uint8Array but has different internal structure)
- Additional issue: Blob data returned as plain JS array instead of ArrayBuffer/Uint8Array
- Repro repo provided: https://github.com/sdarnell/cf-svelte
- Drizzle ORM types require Buffer, causing friction
- Documentation unclear on allowable blob types
Recommendation
Status: KEEP OPEN
Reasoning: Valid bug where Buffer (a common Node.js type) fails but Uint8Array works. Since Buffer extends Uint8Array, this should work. The assertion in devalue.ts needs to handle Buffer correctly. No comments or engagement on this issue despite being over a year old.
Action: Fix miniflare's devalue handler to accept Buffer type. Also investigate the blob return type issue (returning plain array instead of typed array).
Suggested Comment
This issue is still valid. The miniflare devalue handler at
src/workers/core/devalue.tsneeds to handleBuffertype (which extendsUint8Array).Workaround: Convert Buffer to Uint8Array before passing to D1:
const data = new Uint8Array(buffer);
Notes & Feedback (0)
No notes yet.