{"record":{"id":"125ac97847388f96","repo":"sveltejs/kit","slug":"you-must-specify-the-assets-directory-key-in-c","errorCode":null,"errorMessage":"You must specify the `assets.directory` key in ${config_path}. Consult https://developers.cloudflare.com/workers/static-assets/binding/#directory","messagePattern":"You must specify the `assets\\.directory` key in (.+?)\\. Consult https://developers\\.cloudflare\\.com/workers/static-assets/binding/#directory","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-cloudflare/utils.js","lineNumber":34,"sourceCode":"\treturn true;\n}\n\n/**\n * @param {import('wrangler').Unstable_Config} wrangler_config\n */\nexport function validate_worker_settings(wrangler_config) {\n\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}","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-cloudflare/utils.js#L16-L52","documentation":"Workers Static Assets require an `assets.directory` field so Cloudflare knows where the built static files live, and the adapter needs it to deploy the client build. When the config declares a `main` entry (a Worker script) or an `assets` object but omits `assets.directory`, validation fails at build time.","triggerScenarios":"wrangler config contains `main` (a worker entry point) or an `assets` object, but `assets.directory` is missing or empty — checked during `vite build` via validate_wrangler_config.","commonSituations":"Hand-editing wrangler.jsonc and adding `assets.binding` but forgetting `directory`; typos like `asset.directory`; partial migration from `site` to `assets`.","solutions":["Add `\"assets\": { \"directory\": \"<built-client-path>\" }` to wrangler.jsonc (typically the adapter writes this — ensure you aren't overwriting it).","Fix typos: the key must be exactly `assets.directory`, not nested differently.","If you have no `main` and no custom assets config, remove the partial `assets`/`main` keys and let the adapter configure them.","Re-run `vite build` after editing so the adapter can regenerate/validate the config."],"exampleFix":"// before\n{\n  \"main\": \"src/worker.js\",\n  \"assets\": { \"binding\": \"ASSETS\" }\n}\n\n// after\n{\n  \"main\": \"src/worker.js\",\n  \"assets\": { \"directory\": \".svelte-kit/cloudflare\", \"binding\": \"ASSETS\" }\n}","handlingStrategy":"validation","validationCode":"if ((cfg.main || cfg.assets) && !cfg.assets?.directory) {\n  throw new Error('wrangler config needs assets.directory when main or assets is set');\n}","typeGuard":"function hasAssetsDirectory(config) {\n  return typeof config?.assets?.directory === 'string' && config.assets.directory.length > 0;\n}","tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (String(e).includes('`assets.directory`')) {\n    console.error('Add assets.directory to wrangler config');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Run `vite build` and inspect the generated wrangler config before hand-editing it.","Always pair `assets.binding` with `assets.directory`.","Avoid partial `assets` objects — configure both directory and binding together.","Validate wrangler.jsonc with `npx wrangler deploy --dry-run` before deploying."],"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"}