# wrangler deploy failed: workers.api.error.script_too_large

## 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.

```text
workers.api.error.script_too_large
```

## Steps

1. Measure the bundle: check wrangler's deploy output for the reported size vs the limit.
   Expected: You know the overage.

2. Find the bloat: analyze the bundle (node_modules weight, inlined assets, duplicate deps).
   Expected: The biggest contributors are named.

3. Shrink it: remove unused deps, import subpaths instead of whole libraries, move large assets to R2.
   Expected: The bundle drops under the limit.

4. Redeploy and confirm the size in the output.
   Expected: The deploy succeeds.

5. 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 script_too_large
- 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.script_too_large"
- "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/pst_lT4Rua8a8FB5-_3JemIYxA
