workerd error: env.ASSETS binding missing on custom domain route
Fixes the missing ASSETS binding when serving static assets from a Worker on a custom domain. This skill shows how to add the [assets] section to wrangler.toml, serve through env.ASSETS.fetch with an SPA fallback, and attach the domain route to the worker. Use it when env.ASSETS is undefined on a custom domain.
Fix env.ASSETS binding missing on custom domain route
TL;DR
env.ASSETS only exists when the worker is configured with static assets. Add an [assets] section to wrangler.toml pointing at your build output directory, serve static paths through env.ASSETS.fetch(request) with an index.html fallback for SPA routes, and make sure the custom domain route is attached to the worker.
Verbatim error
workerd error: env.ASSETS binding missing on custom domain routeSteps
- Open wrangler.toml and add
[assets]withdirectoryset to your build output, e.g.directory = "./dist". Expected: the section is present and the path exists. - Deploy with
npx wrangler deploy. Expected: the deploy output mentions the assets upload. - In the worker, serve static paths with
env.ASSETS.fetch(request). Expected: asset requests return 200. - Add an SPA fallback: if the ASSETS fetch returns 404, fetch
index.htmlfrom ASSETS instead. Expected: client-side routes render. - Attach the custom domain route to the worker (dashboard custom domains tab or a wrangler route). Expected: the domain serves this worker.
- Verify on the custom domain: fetch a static file and an SPA route directly. Expected: both return 200 with no binding errors.
Use this when
env.ASSETSis undefined on a custom domain- Assets work on workers.dev but not on the custom domain
- You migrated from Pages to Workers static assets and the binding vanished
Not for this skill when
- The assets directory path is wrong (files not found is a different error)
- You serve assets from R2 with your own code (no ASSETS binding involved)
- You are on the legacy Workers Sites setup (different mechanism)
Variant phrasings
- ASSETS binding undefined custom domain
- workers static assets not served
- env.ASSETS.fetch 404
- workers assets binding missing
Why it happens
The ASSETS binding is synthesized from the [assets] config at deploy time. Without that section, env.ASSETS is undefined, and custom-domain routes - which do not get the default workers.dev asset handling - expose the gap that workers.dev hides.
Edge cases
- The
[assets]directory must exist at deploy time or the deploy fails. _headersand_redirectsfiles inside the assets directory are honored by the asset serving.- Large asset counts slow down deploys; keep build artifacts like source maps out of the directory if you do not serve them.
Provenance
Resolved from the public thread: https://vectle.com/posts/pstEAekhAvUlUqM4M-csLhww
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.