Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/wrangler/gotchas.md
1# Wrangler Common Issues23## Common Errors45### "Binding ID vs name mismatch"67**Cause:** Confusion between binding name (code) and resource ID8**Solution:** Bindings use `binding` (code name) and `id`/`database_id`/`bucket_name` (resource ID). Preview bindings need separate IDs: `preview_id`, `preview_database_id`910### "Environment not inheriting config"1112**Cause:** Non-inheritable keys not redefined per environment13**Solution:** Non-inheritable keys (bindings, vars) must be redefined per environment. Inheritable keys (routes, compatibility_date) can be overridden1415### "Local dev behavior differs from production"1617**Cause:** Using local simulation instead of remote execution18**Solution:** Choose appropriate remote mode:19- `wrangler dev` (default): Local simulation, fast, limited accuracy20- `wrangler dev --remote`: Full remote execution, production-accurate, slower21- Use `remote: "minimal"` in tests for fast tests with real remote bindings2223### "startWorker doesn't match production"2425**Cause:** Using local mode when remote resources needed26**Solution:** Use `remote` option:27```typescript28const worker = await startWorker({29config: "wrangler.jsonc",30remote: true // or "minimal" for faster tests31});32```3334### "Unexpected runtime changes"3536**Cause:** Missing compatibility_date37**Solution:** Always set `compatibility_date`:38```jsonc39{ "compatibility_date": "2025-01-01" }40```4142### "Durable Object binding not working"4344**Cause:** Missing script_name for external DOs45**Solution:** Always specify `script_name` for external Durable Objects:46```jsonc47{48"durable_objects": {49"bindings": [50{ "name": "MY_DO", "class_name": "MyDO", "script_name": "my-worker" }51]52}53}54```5556For local DOs in same Worker, `script_name` is optional.5758### "Auto-provisioned resources not appearing"5960**Cause:** IDs written back to config on first deploy, but config not reloaded61**Solution:** After first deploy with auto-provisioning, config file is updated with IDs. Commit the updated config. On subsequent deploys, existing resources are reused.6263### "Secrets not available in local dev"6465**Cause:** Secrets set with `wrangler secret put` only work in deployed Workers66**Solution:** For local dev, use `.dev.vars`6768### "Node.js compatibility error"6970**Cause:** Missing Node.js compatibility flag71**Solution:** Some bindings (Hyperdrive with `pg`) require:72```jsonc73{ "compatibility_flags": ["nodejs_compat"] }74```7576### "Workers Assets 404 errors"7778**Cause:** Asset path mismatch or incorrect `html_handling`79**Solution:**80- Check `assets.directory` points to correct build output81- Set `html_handling: "auto-trailing-slash"` for SPAs82- Use `not_found_handling: "single-page-application"` to serve index.html for 404s83```jsonc84{85"assets": {86"directory": "./dist",87"html_handling": "auto-trailing-slash",88"not_found_handling": "single-page-application"89}90}91```9293### "Placement not reducing latency"9495**Cause:** Misunderstanding of Smart Placement96**Solution:** Smart Placement only helps when Worker accesses D1 or Durable Objects. It doesn't affect KV, R2, or external API latency.97```jsonc98{ "placement": { "mode": "smart" } } // Only beneficial with D1/DOs99```100101### "unstable_startWorker not found"102103**Cause:** Using outdated API104**Solution:** Use stable `startWorker` instead:105```typescript106import { startWorker } from "wrangler"; // Not unstable_startWorker107```108109### "outboundService not mocking fetch"110111**Cause:** Mock function not returning Response112**Solution:** Always return Response, use `fetch(req)` for passthrough:113```typescript114const worker = await startWorker({115outboundService: (req) => {116if (shouldMock(req)) {117return new Response("mocked");118}119return fetch(req); // Required for non-mocked requests120}121});122```123124## Limits125126| Resource/Limit | Value | Notes |127|----------------|-------|-------|128| Bindings per Worker | 64 | Total across all types |129| Environments | Unlimited | Named envs in config |130| Config file size | ~1MB | Keep reasonable |131| Workers Assets size | 25 MB | Per deployment |132| Workers Assets files | 20,000 | Max number of files |133| Script size (compressed) | 1 MB | Free, 10 MB paid |134| CPU time | 10ms | Free, 30s default (5min max) paid |135| Subrequest limit | 50 | Free, 10,000 paid |136137## Troubleshooting138139### Authentication Issues140```bash141wrangler logout142wrangler login143wrangler whoami144```145146### Configuration Errors147```bash148wrangler check startup # Profile Worker startup time and detect scripts exceeding the startup time limit149```150Use wrangler.jsonc with `$schema` for validation.151152### Binding Not Available153- Check binding exists in config154- For environments, ensure binding defined for that env155- Local dev: some bindings need `--remote`156157### Deployment Failures158```bash159wrangler tail # Check logs160wrangler deploy --dry-run # Validate161wrangler whoami # Check account limits162```163164### Local Development Issues165```bash166rm -rf .wrangler/state # Clear local state167wrangler dev --remote # Use remote bindings168wrangler dev --persist-to ./local-state # Custom persist location169wrangler dev --inspector-port 9229 # Enable debugging170```171172### Testing Issues173```bash174# If tests hang, ensure dispose() is called175worker.dispose() // Always cleanup176177# If bindings don't work in tests178const worker = await startWorker({179config: "wrangler.jsonc",180remote: "minimal" // Use remote bindings181});182```183184## Resources185186- Docs: https://developers.cloudflare.com/workers/wrangler/187- Config: https://developers.cloudflare.com/workers/wrangler/configuration/188- Commands: https://developers.cloudflare.com/workers/wrangler/commands/189- Examples: https://github.com/cloudflare/workers-sdk/tree/main/templates190- Discord: https://discord.gg/cloudflaredev191192## See Also193194- [README.md](./README.md) - Commands195- [configuration.md](./configuration.md) - Config196- [api.md](./api.md) - Programmatic API197- [patterns.md](./patterns.md) - Workflows198