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/workerd/gotchas.md
1# Workerd Gotchas23## Common Errors45### "Missing compatibility date"6**Cause:** Compatibility date not set7**Solution:**8❌ Wrong:9```capnp10const worker :Workerd.Worker = (11serviceWorkerScript = embed "worker.js"12)13```1415✅ Correct:16```capnp17const worker :Workerd.Worker = (18serviceWorkerScript = embed "worker.js",19compatibilityDate = "2024-01-15" # Always set!20)21```2223### Wrong Binding Type24**Problem:** JSON not parsed25**Cause:** Using `text = '{"key":"value"}'` instead of `json`26**Solution:** Use `json = '{"key":"value"}'` for parsed objects2728### Service vs Namespace29**Problem:** Cannot create DO instance30**Cause:** Using `service = "room-service"` for Durable Object31**Solution:** Use `durableObjectNamespace = "Room"` for DO bindings3233### Module Name Mismatch34**Problem:** Import fails35**Cause:** Module name includes path: `name = "src/index.js"`36**Solution:** Use simple names: `name = "index.js"`, embed with path3738## Network Access3940**Problem:** Fetch fails with network error41**Cause:** No network service configured (workerd has no global fetch)42**Solution:** Add network service binding:43```capnp44services = [(name = "internet", network = (allow = ["public"]))]45bindings = [(name = "NET", service = "internet")]46```4748Or external service:49```capnp50bindings = [(name = "API", service = (external = (address = "api.com:443", http = (style = tls))))]51```5253### "Worker not responding"54**Cause:** Socket misconfigured, no fetch handler, or port unavailable55**Solution:** Verify socket `address` matches, worker exports `fetch()`, port available5657### "Binding not found"58**Cause:** Name mismatch or service doesn't exist59**Solution:** Check binding name in config matches code (`env.BINDING` for ES modules)6061### "Module not found"62**Cause:** Module name doesn't match import or bad embed path63**Solution:** Module `name` must match import path exactly, verify `embed` path6465### "Compatibility error"66**Cause:** Date not set or API unavailable on that date67**Solution:** Set `compatibilityDate`, verify API available on that date6869## Performance Issues7071**Problem:** High memory usage72**Cause:** Large caches or many isolates73**Solution:** Set cache limits, reduce isolate count, or use V8 flags (caution)7475**Problem:** Slow startup76**Cause:** Many modules or complex config77**Solution:** Compile to binary (`workerd compile`), reduce imports7879**Problem:** Request timeouts80**Cause:** External service issues or DNS problems81**Solution:** Check connectivity, DNS resolution, TLS handshake8283## Build Issues8485**Problem:** Cap'n Proto syntax errors86**Cause:** Invalid config or missing schema87**Solution:** Install capnproto tools, validate: `capnp compile -I. config.capnp`8889**Problem:** Embed path not found90**Cause:** Path relative to config file91**Solution:** Use correct relative path or absolute path9293**Problem:** V8 flags cause crashes94**Cause:** Unsafe V8 flags95**Solution:** ⚠️ V8 flags unsupported in production. Test thoroughly before use.9697## Security Issues9899**Problem:** Hardcoded secrets in config100**Cause:** `text` binding with secret value101**Solution:** Use `fromEnvironment` to load from env vars102103**Problem:** Overly broad network access104**Cause:** `network = (allow = ["*"])`105**Solution:** Restrict to `allow = ["public"]` or specific hosts106107**Problem:** Extractable crypto keys108**Cause:** `cryptoKey = (extractable = true, ...)`109**Solution:** Set `extractable = false` unless export required110111## Compatibility Changes112113**Problem:** Breaking changes after compat date update114**Cause:** New flags enabled between dates115**Solution:** Review [compat dates docs](https://developers.cloudflare.com/workers/configuration/compatibility-dates/), test locally first116117**Problem:** "Compatibility date not supported"118**Cause:** Workerd version older than compat date119**Solution:** Update workerd binary (version = max compat date supported)120121## Limits122123| Resource/Limit | Value | Notes |124|----------------|-------|-------|125| V8 flags | Unsupported in production | Use with caution |126| Compatibility date | Must match workerd version | Update if mismatch |127| Module count | Affects startup time | Many imports slow |128129## Troubleshooting Steps1301311. **Enable verbose logging**: `workerd serve config.capnp --verbose`1322. **Check logs**: Look for error messages, stack traces1333. **Validate config**: `capnp compile -I. config.capnp`1344. **Test bindings**: Log `Object.keys(env)` to verify1355. **Check versions**: Workerd version vs compat date1366. **Isolate issue**: Minimal repro config1377. **Review schema**: [workerd.capnp](https://github.com/cloudflare/workerd/blob/main/src/workerd/server/workerd.capnp)138139See [configuration.md](./configuration.md) for config details, [patterns.md](./patterns.md) for working examples, [api.md](./api.md) for runtime APIs.140