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/pages/gotchas.md
1# Gotchas23## Functions Not Running45**Problem**: Function endpoints return 404 or don't execute6**Causes**: `_routes.json` excludes path; wrong file extension (`.jsx`/`.tsx`); Functions dir not at output root7**Solution**: Check `_routes.json`, rename to `.ts`/`.js`, verify build output structure89## 404 on Static Assets1011**Problem**: Static files not serving12**Causes**: Build output dir misconfigured; Functions catching requests; Advanced mode missing `env.ASSETS.fetch()`13**Solution**: Verify output dir, add exclusions to `_routes.json`, call `env.ASSETS.fetch()` in `_worker.js`1415## Bindings Not Working1617**Problem**: `env.BINDING` undefined or errors18**Causes**: wrangler.jsonc syntax error; wrong binding IDs; missing `.dev.vars`; out-of-sync types19**Solution**: Validate config, verify IDs, create `.dev.vars`, run `npx wrangler types`2021## Build Failures2223**Problem**: Deployment fails during build24**Causes**: Wrong build command/output dir; Node version incompatibility; missing env vars; 20min timeout; OOM25**Solution**: Check Dashboard → Deployments → Build log; verify settings; add `.nvmrc`; optimize build2627## Middleware Not Running2829**Problem**: Middleware doesn't execute30**Causes**: Wrong filename (not `_middleware.ts`); missing `onRequest` export; didn't call `next()`31**Solution**: Rename file with underscore prefix; export handler; call `next()` or return Response3233## Headers/Redirects Not Working3435**Problem**: `_headers` or `_redirects` not applying36**Causes**: Only work for static assets; Functions override; syntax errors; exceeded limits37**Solution**: Set headers in Response object for Functions; verify syntax; check limits (100 headers, 2,100 redirects)3839## TypeScript Errors4041**Problem**: Type errors in Functions code42**Causes**: Types not generated; Env interface doesn't match wrangler.jsonc43**Solution**: Run `npx wrangler types --path='./functions/types.d.ts'`; update Env interface4445## Local Dev Issues4647**Problem**: Dev server errors or bindings don't work48**Causes**: Port conflict; bindings not passed; local vs HTTPS differences49**Solution**: Use `--port=3000`; pass bindings via CLI or wrangler.jsonc; account for HTTP/HTTPS differences5051## Performance Issues5253**Problem**: Slow responses or CPU limit errors54**Causes**: Functions invoked for static assets; cold starts; 10ms CPU limit (free) / 30s default (paid); large bundle55**Solution**: Exclude static via `_routes.json`; optimize hot paths; keep bundle < 1MB5657## Framework-Specific5859### ⚠️ Deprecated Frameworks6061**Next.js**: Official adapter (`@cloudflare/next-on-pages`) **deprecated** and unmaintained.62- **Problem**: No updates since 2024; incompatible with Next.js 15+; missing App Router features63- **Cause**: Cloudflare discontinued official support; community fork exists but limited64- **Solutions**:651. **Recommended**: Use Vercel (official Next.js host)662. **Advanced**: Self-host on Workers using custom adapter (complex, unsupported)673. **Migration**: Switch to SvelteKit/Nuxt (similar DX, full Pages support)6869**Remix**: Official adapter (`@remix-run/cloudflare-pages`) **deprecated**.70- **Problem**: No maintenance from Remix team; compatibility issues with Remix v2+71- **Cause**: Remix team deprecated all framework adapters72- **Solutions**:731. **Recommended**: Migrate to SvelteKit (similar file-based routing, better DX)742. **Alternative**: Use Astro (static-first with optional SSR)753. **Workaround**: Continue using deprecated adapter (no future support)7677### ✅ Supported Frameworks7879**SvelteKit**:80- Use `@sveltejs/adapter-cloudflare`81- Access bindings via `platform.env` in server load functions82- Set `platform: 'cloudflare'` in `svelte.config.js`8384**Astro**:85- Built-in Cloudflare adapter86- Access bindings via `Astro.locals.runtime.env`8788**Nuxt**:89- Set `nitro.preset: 'cloudflare-pages'` in `nuxt.config.ts`90- Access bindings via `event.context.cloudflare.env`9192**Qwik, Solid Start**:93- Built-in or official Cloudflare adapters available94- Check respective framework docs for binding access9596## Debugging9798```typescript99// Log request details100console.log('Request:', { method: request.method, url: request.url });101console.log('Env:', Object.keys(env));102console.log('Params:', params);103```104105**View logs**: `npx wrangler pages deployment tail --project-name=my-project`106107## Smart Placement Issues108109### Increased Cold Start Latency110111**Problem**: First requests slower after enabling Smart Placement112**Cause**: Initial optimization period while system learns traffic patterns113**Solution**: Expected behavior during first 24-48 hours; monitor latency trends over time114115### Inconsistent Response Times116117**Problem**: Latency varies significantly across requests during initial deployment118**Cause**: Smart Placement testing different execution locations to find optimal placement119**Solution**: Normal during learning phase; stabilizes after traffic patterns emerge (1-2 days)120121### No Performance Improvement122123**Problem**: Smart Placement enabled but no latency reduction observed124**Cause**: Traffic evenly distributed globally, or no data locality constraints125**Solution**: Smart Placement most effective with centralized data (D1/DO) or regional traffic; disable if no benefit126127## Remote Bindings Issues128129### Accidentally Modified Production Data130131**Problem**: Local dev with `--remote` altered production database/KV132**Cause**: Remote bindings connect directly to production resources; writes are real133**Solution**:134- Use `--remote` only for read-heavy debugging135- Create separate preview environments for testing136- Never use `--remote` for write operations during development137138### Remote Binding Auth Errors139140**Problem**: `npx wrangler pages dev --remote` fails with "Unauthorized" or auth error141**Cause**: Not logged in, session expired, or insufficient account permissions142**Solution**:1431. Run `npx wrangler login` to re-authenticate1442. Verify account has access to project and bindings1453. Check binding IDs match production configuration146147### Slow Local Dev with Remote Bindings148149**Problem**: Local dev server slow when using `--remote`150**Cause**: Every request makes network calls to production bindings151**Solution**: Use local bindings for development; reserve `--remote` for final validation152153## Common Errors154155### "Module not found"156**Cause**: Dependencies not bundled or build output incorrect157**Solution**: Check build output directory, ensure dependencies bundled158159### "Binding not found"160**Cause**: Binding not configured or types out of sync161**Solution**: Verify wrangler.jsonc, run `npx wrangler types`162163### "Request exceeded CPU limit"164**Cause**: Code execution too slow or heavy compute165**Solution**: Optimize hot paths, upgrade to Workers Paid166167### "Script too large"168**Cause**: Bundle size exceeds limit169**Solution**: Tree-shake, use dynamic imports, code-split170171### "Too many subrequests"172**Cause**: Exceeded 50 subrequest limit173**Solution**: Batch or reduce fetch calls174175### "KV key not found"176**Cause**: Key doesn't exist or wrong namespace177**Solution**: Check namespace matches environment178179### "D1 error"180**Cause**: Wrong database_id or missing migrations181**Solution**: Verify config, run `wrangler d1 migrations list`182183## Limits Reference (Jan 2026)184185| Resource | Free | Paid |186|----------|------|------|187| Functions Requests | 100k/day | Unlimited |188| CPU Time | 10ms/req | 30s default, 5min max |189| Memory | 128MB | 128MB |190| Script Size | 1MB | 10MB |191| Subrequests | 50/req | 10,000/req |192| Deployments | 500/month | 5,000/month |193194**Tip**: Hitting CPU limit? Optimize hot paths or upgrade to Workers Paid plan.195196[Full limits](https://developers.cloudflare.com/pages/platform/limits/)197198## Getting Help1992001. Check [Pages Docs](https://developers.cloudflare.com/pages/)2012. Search [Discord #functions](https://discord.com/channels/595317990191398933/910978223968518144)2023. Review [Workers Examples](https://developers.cloudflare.com/workers/examples/)2034. Check framework-specific docs/adapters204