#10726 wrangler command that offer to add to wrangler.jsonc don't respect existing binding to same resource
Confirmed bug: resource creation commands (d1 create, kv namespace create, etc.) add bindings to config without checking for existing bindings with same name, causing duplicate binding errors. Maintainer confirmed as bug in PR #10414 logic.
Keep open for fix - need to check for existing bindings before insertion in add-created-resource-config.ts
Analysis Report
Issue Review: cloudflare/workers-sdk#10726
Summary
wrangler d1 create (and other resource creation commands) offer to add bindings to wrangler.jsonc but don't check if a binding with the same name/resource already exists, resulting in duplicate binding errors.
Findings
- Created: 2025-09-22
- Updated: 2025-09-23
- Version: Wrangler 4.38.0 → 4.60.0 (current)
- Component: Wrangler - config patching for resource creation commands
- Labels:
bug,d1 - Comments: 2 (both from Cloudflare maintainers)
Key Evidence
- Valid bug identified by maintainer: @petebacondarwin confirmed this is a bug in PR #10414's logic, not specific to D1 - affects all resource creation commands (KV, R2, etc.)
- Root cause identified: The
createdResourceConfig()function inpackages/wrangler/src/utils/add-created-resource-config.tscallsexperimental_patchConfig()withisArrayInsertion=true, which always appends new array items without checking for existing bindings with the same name - No fix found: Searched for related PRs and changelog entries - no evidence of a fix being merged
- Reproduction provided: Reporter provided a clear minimal reproduction at https://github.com/irvinebroque/workers-for-platforms-example/pull/1/files
- Common pattern affected: Users often add binding stubs with empty IDs that they later fill in - this workflow is now broken
Technical Details
The issue occurs in the add-created-resource-config.ts file which handles all resource creation commands:
- When creating a resource (D1, KV, R2, etc.), Wrangler offers to update
wrangler.jsonc - If the user accepts, it calls
experimental_patchConfig()with the new binding experimental_patchConfig()usesisArrayInsertion=truewhich appends to the array without checking existing entries- If a binding with the same name already exists (common when users have pre-defined binding stubs with empty IDs), the config ends up with duplicate bindings
- This causes a validation error: "Binding X assigned to multiple Y bindings"
Fix suggestion: Before inserting, the code should check if a binding with the same name already exists and either:
- Update the existing binding's ID/properties instead of creating a new one
- Prompt the user about the duplicate and ask how to proceed
Recommendation
Status: KEEP OPEN
Reasoning: This is a confirmed, reproducible bug affecting a common workflow. The root cause is clearly identified in the add-created-resource-config.ts utility, and a maintainer has acknowledged it. No fix has been merged since the issue was reported 4 months ago.
Action: Keep open for engineering to fix. The fix should check for existing bindings by name before inserting and either update them or prompt the user.
Suggested Comment
N/A - Issue is valid and should remain open for a fix.
Notes & Feedback (0)
No notes yet.