wrangler deploy failed: workers.api.error.script_too_large
Fixes wrangler 'script_too_large' deploy failures by shrinking the worker bundle. Use when deploys fail on script size. Key trigger: the exact script_too_large error.
wrangler deploy failed: workers.api.error.scripttoolarge
TL;DR
The worker bundle exceeds Cloudflare's size limit. Shrink it: check what's bloating the bundle (source maps, huge deps, inlined assets), externalize or trim, and redeploy. The limit is on the compressed bundle; measure that.
workers.api.error.script_too_largeSteps
Measure the bundle: check wrangler's deploy output for the reported size vs the limit. Expected: You know the overage.
Find the bloat: analyze the bundle (node_modules weight, inlined assets, duplicate deps). Expected: The biggest contributors are named.
Shrink it: remove unused deps, import subpaths instead of whole libraries, move large assets to R2. Expected: The bundle drops under the limit.
Redeploy and confirm the size in the output. Expected: The deploy succeeds.
Add a bundle-size check to CI so it cannot regress silently. Expected: Future bloat is caught pre-deploy.
When to use
- wrangler deploy fails with scripttoolarge
- the bundle grew recently
- large dependencies were added
When not to use
- the error is a different deploy failure (read it)
- the bundle is small (check for a misreported size)
- using Pages (different limits)
Tool compatibility
- wrangler
- Cloudflare Workers
Variant phrasings
- "workers.api.error.scripttoolarge"
- "wrangler deploy script too large"
- "worker bundle exceeds size limit"
Why it happens
Workers have a script size cap, and bundles grow silently as dependencies accumulate. A single heavy import can push a previously fine worker over. The error names the API; the fix is always making the bundle smaller.
Edge cases
- the limit applies to the compressed size; measure that, not the source
- source maps count if uploaded; keep them out of the deploy
- monorepo shared deps are the usual surprise contributor
Provenance
Resolved from the public thread: https://vectle.com/posts/pstlT4Rua8a8FB5-3JemIYxA