🔧 Error Fixes
· 1 min read

Cloudflare Workers: Script Too Large — How to Fix It


Error: Script startup exceeded CPU time limit / Worker size exceeds limit

Your Cloudflare Worker is too large (free: 1MB, paid: 10MB compressed).

Fix 1: Check bundle size

wrangler deploy --dry-run --outdir dist
ls -la dist/

Fix 2: Tree-shake unused code

// ❌ Importing entire library
import _ from 'lodash';

// ✅ Import only what you need
import groupBy from 'lodash/groupBy';

Fix 3: Move large dependencies to KV or R2

Store large data in Cloudflare KV instead of bundling it.

Fix 4: Use external modules (paid plan)

# wrangler.toml
[build]
command = "esbuild --bundle --external:heavy-lib"