{"record":{"id":"fe2a9c416cf902e0","repo":"sveltejs/kit","slug":"you-must-specify-the-assets-binding-key-in-con","errorCode":null,"errorMessage":"You must specify the `assets.binding` key in ${config_path} before deploying your Worker. Consult https://developers.cloudflare.com/workers/static-assets/binding/#binding","messagePattern":"You must specify the `assets\\.binding` key in (.+?) before deploying your Worker\\. Consult https://developers\\.cloudflare\\.com/workers/static-assets/binding/#binding","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-cloudflare/utils.js","lineNumber":41,"sourceCode":"\tconst config_path = wrangler_config.configPath || 'your wrangler.jsonc file';\n\n\t// we don't support workers sites\n\tif (wrangler_config.site) {\n\t\tthrow new Error(\n\t\t\t`You must remove all \\`site\\` keys in ${config_path}. Consult https://svelte.dev/docs/kit/adapter-cloudflare#Migrating-from-Workers-Sites`\n\t\t);\n\t}\n\n\t// we need the `assets.directory` key so that the static assets are deployed\n\tif ((wrangler_config.main || wrangler_config.assets) && !wrangler_config.assets?.directory) {\n\t\tthrow new Error(\n\t\t\t`You must specify the \\`assets.directory\\` key in ${config_path}. Consult https://developers.cloudflare.com/workers/static-assets/binding/#directory`\n\t\t);\n\t}\n\n\t// we need the `assets.binding` key so that the Worker can access the static assets\n\tif (wrangler_config.main && !wrangler_config.assets?.binding) {\n\t\tthrow new Error(\n\t\t\t`You must specify the \\`assets.binding\\` key in ${config_path} before deploying your Worker. Consult https://developers.cloudflare.com/workers/static-assets/binding/#binding`\n\t\t);\n\t}\n\n\t// the user might have forgot the `main` key or should remove the `assets.binding`\n\t// key to deploy static assets without a Worker\n\tif (!wrangler_config.main && wrangler_config.assets?.binding) {\n\t\tthrow new Error(\n\t\t\t`You must specify the \\`main\\` key in ${config_path} if you want to deploy a Worker alongside your static assets. Otherwise, remove the \\`assets.binding\\` key if you only want to deploy static assets.`\n\t\t);\n\t}\n}\n\n/**\n * Extracts the redirect source from each line of a [_redirects](https://developers.cloudflare.com/pages/configuration/redirects/)\n * file so we can exclude them in [_routes.json](https://developers.cloudflare.com/pages/functions/routing/#create-a-_routesjson-file)\n * to ensure the redirect is invoked instead of the Cloudflare Worker.\n * @param {string} file_contents","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-cloudflare/utils.js#L23-L59","documentation":"When a Worker (`main`) is deployed alongside static assets, an `assets.binding` must be defined so the Worker script can fetch static assets through an env binding (typically ASSETS). Validation fails during build if `main` is set but `assets.binding` is missing.","triggerScenarios":"wrangler config has `main: \"<worker entry>\"` and `assets` (with directory) but no `assets.binding`, checked during `vite build` / deploy via validate_wrangler_config.","commonSituations":"Adding a custom worker entry to a previously static-only project; deleting the binding while keeping `main`; scaffolding configs from non-adapter templates.","solutions":["Add `\"binding\": \"ASSETS\"` inside the `assets` object in wrangler.jsonc.","Access the assets through `platform.env.ASSETS.fetch(...)` in your worker code with that binding name.","If you don't actually need a Worker script, remove `main` instead so assets deploy alone."],"exampleFix":"// before\n{\n  \"main\": \"build/server/index.js\",\n  \"assets\": { \"directory\": \".svelte-kit/cloudflare\" }\n}\n\n// after\n{\n  \"main\": \"build/server/index.js\",\n  \"assets\": { \"directory\": \".svelte-kit/cloudflare\", \"binding\": \"ASSETS\" }\n}","handlingStrategy":"validation","validationCode":"if (cfg.main && !cfg.assets?.binding) {\n  throw new Error('wrangler config needs assets.binding when main is set');\n}","typeGuard":"function workerCanAccessAssets(config) {\n  return typeof config?.main === 'string' && typeof config?.assets?.binding === 'string';\n}","tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (String(e).includes('`assets.binding`')) {\n    console.error('Add assets.binding (e.g. \"ASSETS\") to wrangler config');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Keep main + assets.directory + assets.binding configured as a set.","Use the conventional binding name ASSETS and access via platform.env.ASSETS.","Run `npx wrangler deploy --dry-run` to catch config gaps pre-deploy.","Re-run the adapter build after manually editing wrangler config to re-validate."],"tags":["cloudflare","wrangler-config","adapter-config","static-assets"],"backgroundTag":"missing-required-config-field","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}