{"record":{"id":"acdb049f8104300e","repo":"sveltejs/kit","slug":"you-must-specify-the-main-key-in-config-path","errorCode":null,"errorMessage":"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.","messagePattern":"You must specify the `main` key in (.+?) 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\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/adapter-cloudflare/utils.js","lineNumber":49,"sourceCode":"\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\n * @returns {string[]}\n */\nexport function parse_redirects(file_contents) {\n\t/** @type {string[]} */\n\tconst redirects = [];\n\n\tfor (const line of file_contents.split('\\n')) {\n\t\tconst content = line.trim();","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/adapter-cloudflare/utils.js#L31-L67","documentation":"This is the inverse of error 35: an `assets.binding` exists, which declares 'a Worker will serve/interact with assets', but no `main` key names the Worker script. The adapter cannot tell whether you forgot the `main` entry or meant a static-only deployment, so it throws with both remediation options.","triggerScenarios":"wrangler config defines `assets.binding` (and possibly `assets.directory`) but has no top-level `main` key, encountered during the adapter's config validation.","commonSituations":"Deleting the `main` field after restructuring the build; copy-pasting an assets config from a static-assets example into an adapter project; renaming the worker entry and removing `main` accidentally.","solutions":["Add `\"main\": \"<worker entry point>\"` to wrangler.jsonc if you want a Worker alongside static assets (the adapter normally sets this to the built server).","Remove `assets.binding` if you only want to serve static assets with no Worker.","Re-run `vite build` and let the adapter rewrite the config before hand-editing further."],"exampleFix":"// before\n{\n  \"assets\": { \"directory\": \".svelte-kit/cloudflare\", \"binding\": \"ASSETS\" }\n}\n\n// after (Worker deploy)\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('assets.binding requires a main worker entry, or remove the binding');\n}","typeGuard":"function isStaticOnlyConfig(config) {\n  return !config?.main && !config?.assets?.binding;\n}","tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (String(e).includes('`main` key')) {\n    console.error('Add `main` or remove assets.binding');\n    process.exit(1);\n  }\n  throw e;\n}","preventionTips":["Decide explicitly: static-only (no binding, no main) or Worker deploy (main + binding).","Never delete `main` from adapter-generated wrangler configs.","Diff your wrangler config against the adapter-generated one after builds.","Validate 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"}