TL;DR: Make the WASM module smaller or stop bundling it. Rebuild with size optimizations and strip debug info, and if it is still too big, fetch the module from R2 at runtime and instantiate it from the fetched bytes. The compiled-size cap applies to what ships in the bundle.

```text
workerd error: WebAssembly module exceeds compiled size limit
```

1. Confirm the module is the problem. Check the deploy error names the WASM module, and measure the module file size in your project.
   Expected: one .wasm file accounts for most of the bundle weight.

2. Rebuild for size. Compile with size optimization flags, run the optimizer over the output, and strip debug symbols and names.
   Expected: the .wasm file shrinks substantially, often by half or more.

3. Redeploy with the optimized module.
   Expected: the deploy succeeds if the module now fits under the cap.

4. If it still does not fit, move the module out of the bundle. Upload the .wasm file to R2, fetch it at runtime, and instantiate from the bytes:
   ```js
   const res = await fetch(moduleUrl);
   const bytes = await res.arrayBuffer();
   const mod = await WebAssembly.compile(bytes);
   ```
   Expected: the bundle stays small, the deploy succeeds, and the module loads on first use.

5. Cache the compiled module in a global so each isolate compiles it once.
   Expected: first request pays the compile cost, later requests reuse it.

6. Verify cold starts still pass the startup CPU budget with the runtime load in place.
   Expected: no startup errors in tail, and the WASM-backed path works end to end.

## Use this when
- the deploy fails naming a WASM module and the compiled size limit
- adding an image, crypto, or parser library that ships WASM broke a previously working deploy
- the .wasm file is megabytes in size
- you need the WASM functionality but the bundle cannot carry it

## Not for this skill when
- the deploy fails on total script size without mentioning WASM (that is the bundle size limit)
- the module loads but traps at runtime (that is a WASM logic bug, not a size limit)
- the error is about WASM compilation time rather than size
- you can replace the WASM dependency with a pure-JS alternative that fits

## Variant phrasings
- Cloudflare Worker WASM too large deploy fails
- "WebAssembly module exceeds compiled size limit"
- wasm module size limit workers deploy
- bundle WASM in Cloudflare Worker fails
- workerd wasm compiled size exceeded

## Why it happens
The platform caps how large a compiled WASM module inside a worker bundle may be, because big modules cost compile time and memory on every cold start. Debug builds and unoptimized output bloat modules far past what the cap allows. Optimizer builds strip what the cap counts, and runtime loading moves the bytes out of the bundle entirely so the cap no longer applies to them.

## Edge cases
- Runtime-loaded modules still cost compile CPU on first use. Budget that against the startup or request CPU limit.
- Fetching the module from R2 on every cold start adds latency. Cache the compiled module in a global per isolate.
- Some WASM toolchains embed the module as base64 in JS. That counts against the bundle too, and base64 inflates size by a third. Keep the .wasm file separate.
- Version the R2 object with the module. A stale cached module after a logic change is a nasty bug to chase.
- Instantiating from fetched bytes requires the bytes to be complete before compile. Do not stream partial bytes into the compiler.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_pOEACJyMZwkz6yULkLoyDA
