#9578 Export D1 DataBase Error: cell.replace is not a function
PR #9866 (merged 2025-07-18) fixes the cell.replace error for mismatched data types. Fix is in wrangler versions after 4.20.0. Issue not explicitly closed by PR.
Ask reporter to verify with wrangler 4.60.0. If persists for remote exports, may indicate different code path issue.
Analysis Report
Issue Review: cloudflare/workers-sdk#9578
Summary
D1 export fails with cell.replace is not a function error when database contains values with mismatched data types.
Findings
- Created: 2025-06-12
- Updated: 2025-07-07
- Version: wrangler 4.16.1 / 4.19.2 / 4.20.0 -> 4.60.0 (current)
- Component: D1 (wrangler)
- Labels: bug, internal, d1
- Comments: 0
Key Evidence
- PR #9866 (merged 2025-07-18) and backport PR #10035 (merged 2025-07-22) fix this exact issue: "fix: escape column names and handle mismatched data types in D1 SQL dump"
- The fix addresses the root cause: the code was checking the column's declared type (
colType) instead of the actual runtime type (cellType) before formatting cells - When a non-string value was encountered in a TEXT column, the code would call
cell.replace()on a non-string, causing the error - The fix changes the logic to check
typeof cell === "string"instead ofcolType === "TEXT" - Issue was reported on 2025-06-12, fix was merged on 2025-07-18 (36 days after the issue was created)
- The PR explicitly fixes related issues #8377, #6357, #5920, and mentions #8226
Recommendation
Status: NEEDS VERIFICATION
Reasoning: The cell.replace is not a function error is fixed by PR #9866, which handles SQLite's dynamic typing properly. The fix was merged over 6 months ago and is available in wrangler versions after 4.20.0 (which the reporter tested). However, since the issue was not explicitly closed by the PR and the fix was for local/miniflare D1 export (not remote), there may be a different code path for remote exports that still has this bug.
Action: Ask the reporter to verify with the latest wrangler version (4.60.0). If the issue persists for remote D1 exports specifically, this may indicate a separate bug in the remote export API path.
Suggested Comment
Hi @axww! A fix for the
cell.replace is not a functionerror was merged in PR #9866 and backported in PR #10035. This fix addresses SQLite's dynamic typing where column values may have different runtime types than their declared column types.Could you please test with the latest wrangler version (4.60.0) and let us know if the issue is resolved?
npm install wrangler@latest npx wrangler d1 export <database-name> --remote --output=export.sqlIf the issue persists, it would be helpful to know:
- What data types are in your database tables (particularly any columns that might have mixed types)?
- Does the export work for a smaller database or specific tables?
Thank you!
Notes & Feedback (0)
No notes yet.