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/miniflare/gotchas.md
1# Gotchas & Troubleshooting23## Miniflare Limitations45**Not supported:**6- Analytics Engine (use mocks)7- Cloudflare Images/Stream8- Browser Rendering API9- Tail Workers10- Workers for Platforms (partial support)1112**Behavior differences from production:**13- Runs workerd locally, not Cloudflare edge14- Storage is local (filesystem/memory), not distributed15- `Request.cf` is cached/mocked, not real edge data16- Performance differs from edge17- Caching implementation may vary slightly1819## Common Errors2021### "Cannot find module"22**Cause:** Module path wrong or `modulesRules` not configured23**Solution:**24```js25new Miniflare({26modules: true,27modulesRules: [{ type: "ESModule", include: ["**/*.js"] }],28});29```3031### "Data not persisting"32**Cause:** Persist paths are files, not directories33**Solution:**34```js35kvPersist: "./data/kv", // Directory, not file36```3738### "Cannot run TypeScript"39**Cause:** Miniflare doesn't transpile TypeScript40**Solution:** Build first with esbuild/tsc, then run compiled JS4142### "`request.cf` is undefined"43**Cause:** CF data not configured44**Solution:**45```js46new Miniflare({ cf: true }); // Or cf: "./cf.json"47```4849### "EADDRINUSE" port conflict50**Cause:** Multiple instances using same port51**Solution:** Use `dispatchFetch()` (no HTTP server) or `port: 0` for auto-assign5253### "Durable Object not found"54**Cause:** Class export doesn't match config name55**Solution:**56```js57export class Counter {} // Must match58new Miniflare({ durableObjects: { COUNTER: "Counter" } });59```6061## Debugging6263**Enable verbose logging:**64```js65import { Log, LogLevel } from "miniflare";66new Miniflare({ log: new Log(LogLevel.DEBUG) });67```6869**Chrome DevTools:**70```js71const url = await mf.getInspectorURL();72console.log(`DevTools: ${url}`); // Open in Chrome73```7475**Inspect bindings:**76```js77const env = await mf.getBindings();78console.log(Object.keys(env));79```8081**Verify storage:**82```js83const ns = await mf.getKVNamespace("TEST");84const { keys } = await ns.list();85```8687## Best Practices8889**✓ Do:**90- Use `dispatchFetch()` for tests (no HTTP server)91- In-memory storage for CI (omit persist options)92- New instances per test for isolation93- Type-safe bindings with interfaces94- `await mf.dispose()` in cleanup9596**✗ Avoid:**97- HTTP server in tests98- Shared instances without cleanup99- Old compatibility dates (use 2026+)100101## Migration Guides102103### From Miniflare 2.x to 3+104105Breaking changes in v3+:106107| v2 | v3+ |108|----|-----|109| `getBindings()` sync | `getBindings()` returns Promise |110| `ready` is void | `ready` returns `Promise<URL>` |111| service-worker-mock | Built on workerd |112| Different options | Restructured constructor |113114**Example migration:**115```js116// v2117const bindings = mf.getBindings();118mf.ready; // void119120// v3+121const bindings = await mf.getBindings();122const url = await mf.ready; // Promise<URL>123```124125### From unstable_dev to Miniflare126127```js128// Old (deprecated)129import { unstable_dev } from "wrangler";130const worker = await unstable_dev("src/index.ts");131132// New133import { Miniflare } from "miniflare";134const mf = new Miniflare({ scriptPath: "src/index.ts" });135```136137### From Wrangler Dev138139Miniflare doesn't auto-read `wrangler.toml`:140141```js142// Translate manually:143new Miniflare({144scriptPath: "dist/worker.js",145compatibilityDate: "2026-01-01",146kvNamespaces: ["KV"],147bindings: { API_KEY: process.env.API_KEY },148});149```150151## Resource Limits152153| Limit | Value | Notes |154|-------|-------|-------|155| CPU time | 30s default | Configurable via `scriptTimeout` |156| Storage | Filesystem | Performance varies by disk |157| Memory | System dependent | No artificial limits |158| Request.cf | Cached/mocked | Not live edge data |159160See [patterns.md](./patterns.md) for testing examples.161