# Fix crypto.subtle digest not available in local dev

## TL;DR

Update wrangler and set a recent `compatibility_date` in wrangler.toml, then fully restart `wrangler dev`. Older local runtimes gate the Web Crypto digest behind a compatibility flag that modern dates enable by default. If you test outside the worker runtime (plain Node test runner), run the tests inside the Cloudflare Workers vitest pool instead so crypto matches production.

## Verbatim error

```text
workerd error: crypto.subtle digest not available in local dev
```

## Steps

1. Check your wrangler version with `npx wrangler --version`. Expected: a current 4.x release; anything much older is the likely cause.
2. Update it: install the latest wrangler as a dev dependency (or your package manager's equivalent). Expected: install completes with no blocking peer-dependency errors.
3. In wrangler.toml set `compatibility_date` to a recent date, for example `compatibility_date = "2026-09-01"`. Expected: the file parses and `wrangler dev` starts without a duplicate-key or invalid-date error.
4. Stop `wrangler dev` completely and start it again (a full restart, not hot reload). Expected: dev boots cleanly.
5. Add a temporary log early in your handler: `console.log(typeof crypto.subtle.digest)`. Expected: it prints `function` in the dev console.
6. If the failure is in unit tests, run them with the Cloudflare Workers vitest pool instead of plain Node. Expected: the digest tests pass locally.

## Use this when

- `crypto.subtle.digest` throws or is undefined in `wrangler dev` but works after deploy
- Hashing, HMAC, or signature verification fails only in local development
- `typeof crypto.subtle.digest` logs `undefined` locally

## Not for this skill when

- Crypto works locally but fails when deployed (that is a deploy-config issue, not this one)
- You need an unsupported algorithm (Workers supports the standard SHA family, HMAC, AES-GCM, P-256/P-384/P-521, Ed25519)
- The failure is `randomUUID` or `getRandomValues` rather than `digest`

## Variant phrasings

- miniflare crypto.subtle undefined
- workerd digest is not a function
- "crypto.subtle not available" wrangler dev
- SubtleCrypto digest missing in local workers runtime

## Why it happens

workerd gates API surface behind compatibility dates and flags. A very old default `compatibility_date` leaves the Web Crypto subprovider disabled in the local runtime, while production workers run with newer defaults. Setting a recent compatibility date and restarting opts the local runtime into the same behavior as production.

## Edge cases

- A `compatibility_date` in the future makes wrangler reject the config, so use a real past date.
- Changing the date can flip other runtime behaviors, so redeploy and smoke-test after the change.
- Some JWT libraries call `digest` at import time; in a plain Node test runner that import fails, so test inside the Cloudflare Workers vitest pool.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_7JdIVH-ar_kCHzemhcs7wQ
