wrangler publish failed: script too large for the workers plan
Fixes wrangler publish and deploy rejections for oversized worker scripts. Use it when the deploy fails on script size; run a dry-run deploy and read the Total Upload figure, which is what the size cap applies to. The key trigger is the 'script too large' style error.
TL;DR
Your bundled worker is over the plan's script size cap, so the API rejects the upload. Run wrangler deploy --dry-run and look at the Total Upload line: the cap applies to the uncompressed bundle size now, not the gzip figure. Shrink the bundle by trimming heavy dependencies or moving large assets out of the script, then deploy again.
Your worker script is over the size limit for your plan (workers.api.error.script_too_large)Steps
- Measure the real bundle size without deploying:
wrangler deploy --dry-runExpected: a "Total Upload" line showing the uncompressed size. If it is over the cap, that is the whole problem.
- Find what is eating the bytes. Check your bundle report or look for the heaviest imports, especially full libraries pulled in for one helper (date, crypto, and image libraries are the usual suspects):
wrangler deploy --dry-run --outdir dist
ls -la distExpected: the output bundle file; compare its size before and after each dependency change to see what moves the needle.
- Shrink the bundle. Replace heavy libraries with smaller equivalents or single-function imports, move large static assets and data files into R2 or KV and fetch them at runtime, and drop source maps from the production build.
Expected: the Total Upload figure drops on the next dry run.
- If the bundle is legitimately large and cannot shrink further, split the worker. Put the heavy path in a second worker and call it over a service binding from the main worker.
Expected: each worker deploys under the cap.
- Redeploy:
wrangler deployExpected: upload succeeds and wrangler prints the deployed URL.
Use this when
wrangler publishorwrangler deployfails with a script-too-large error- The dry-run Total Upload figure is at or over the plan cap
- A new dependency just pushed a previously fine worker over the limit
Not for this skill when
- The deploy fails with "could not find worker script" (entry point problem)
- The worker deploys fine but hits the runtime memory limit (different cap)
- R2, KV, or D1 storage limits are the complaint, not the script bundle
Variant phrasings
- workers.api.error.scripttoolarge
- Your Functions script is over the 1 MiB size limit
- wrangler deploy Total Upload too large
- worker bundle exceeds size limit
Why it happens
Wrangler bundles your code and every dependency into a single script upload. Node-style projects pull in far more than they use, and one careless import can add megabytes. Cloudflare enforces a hard cap on that upload so workers stay fast to distribute to the edge.
Edge cases
- The gzip figure wrangler prints is reference only; the cap is judged on the uncompressed Total Upload.
- WebAssembly modules count toward the bundle, and they compress poorly, so they hurt more than their source size suggests.
- Upgrading the plan raises some limits but the script size cap still applies; shrinking the bundle is the durable fix.
wrangler publishis the old command name; it behaves the same aswrangler deployhere.
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_7QNojgDaVC7wSk6sRRwmZw