#8226 Wrangler crashes trying to export local database with BLOB column
Fixed by PR #9866 (merged 2025-07-18). Fix handles SQLite dynamic typing by escaping values based on runtime type. Released in miniflare 3.20250718.0+ and 4.20250712.2+.
Close with comment explaining fix is available
Analysis Report
Issue #8226: Wrangler crashes trying to export a local database containing a BLOB column
Summary
| Field | Value |
|---|---|
| Issue | #8226 |
| State | OPEN |
| Created | 2025-02-23 |
| Updated | 2025-10-30 |
| Labels | bug, awaiting reporter response, internal, d1 |
Problem Description
When exporting a local D1 database using wrangler d1 export --local, the command crashes with TypeError: cell.replace is not a function if the database contains a BLOB column with binary data. The error occurs in miniflare's outputQuotedEscapedString function which assumes all values are strings.
The reporter stored a 16-byte ArrayBuffer (generated via crypto.randomValues) in a BLOB column. The export command failed, while wrangler d1 execute --command 'SELECT * from table_with_blob' worked correctly.
Reporter's Version: Wrangler 3.109.0, Node.js 23.8.0
Root Cause
The D1 SQL dump logic in miniflare assumed that column types declared in the schema matched the actual stored values. However, SQLite uses dynamic typing, meaning the declared type doesn't enforce the actual value type. The outputQuotedEscapedString function in dumpSql.ts tried to call .replace() on BLOB data (which is not a string), causing the crash.
Fix Analysis
PR #9866 (Main Fix)
- Title: fix: escape column names and handle mismatched data types in D1 SQL dump
- Merged: 2025-07-18
- URL: https://github.com/cloudflare/workers-sdk/pull/9866
The fix:
- Escapes values based on their runtime type instead of the declared column type
- Properly handles SQLite's loose/dynamic typing
- Correctly escapes column and table names to prevent syntax errors
- Adds tests for BLOB export scenarios
PR #10035 (Backport to v3)
- Title: BACKPORT #9866: fix: escape column names and handle mismatched data types in D1 SQL dump
- Merged: 2025-07-22
- URL: https://github.com/cloudflare/workers-sdk/pull/10035
Released Versions
The fix is available in:
- miniflare@3.20250718.0 (v3 line) - Released 2025-07-28
- miniflare@4.20250712.2 and later (v4 line) - Released 2025-07-24
Current Versions (from cache)
- wrangler: 4.60.0
- miniflare: 4.20260120.0
The fix has been in production for approximately 6 months.
Recommendation
CLOSE - This issue has been fixed.
The underlying bug was fixed in PR #9866 (merged 2025-07-18) and backported via PR #10035. The fix has been released in miniflare versions 3.20250718.0+ and 4.20250712.2+.
The issue is still labeled "awaiting reporter response" but the last comment from the reporter was 2025-04-01, before the fix was released. The issue can be closed with a comment informing the reporter of the fix and the versions containing it.
Suggested Close Comment
This issue has been fixed in PR #9866, which was merged on 2025-07-18. The fix handles SQLite's dynamic typing by escaping values based on their runtime type rather than the declared column type.
The fix is available in:
- miniflare 3.20250718.0+ (for Wrangler v3)
- miniflare 4.20250712.2+ (for Wrangler v4)
Please upgrade to the latest version of Wrangler and let us know if you're still experiencing this issue.
Notes & Feedback (0)
No notes yet.