sveltejs/kit · error · Error

You must specify the `assets.directory` key in ${config_path

Error message

You must specify the `assets.directory` key in ${config_path}. Consult https://developers.cloudflare.com/workers/static-assets/binding/#directory

What it means

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.

Source

Thrown at packages/adapter-cloudflare/utils.js:34

	return true;
}

/**
 * @param {import('wrangler').Unstable_Config} wrangler_config
 */
export function validate_worker_settings(wrangler_config) {
	const config_path = wrangler_config.configPath || 'your wrangler.jsonc file';

	// we don't support workers sites
	if (wrangler_config.site) {
		throw new Error(
			`You must remove all \`site\` keys in ${config_path}. Consult https://svelte.dev/docs/kit/adapter-cloudflare#Migrating-from-Workers-Sites`
		);
	}

	// we need the `assets.directory` key so that the static assets are deployed
	if ((wrangler_config.main || wrangler_config.assets) && !wrangler_config.assets?.directory) {
		throw new Error(
			`You must specify the \`assets.directory\` key in ${config_path}. Consult https://developers.cloudflare.com/workers/static-assets/binding/#directory`
		);
	}

	// we need the `assets.binding` key so that the Worker can access the static assets
	if (wrangler_config.main && !wrangler_config.assets?.binding) {
		throw new Error(
			`You must specify the \`assets.binding\` key in ${config_path} before deploying your Worker. Consult https://developers.cloudflare.com/workers/static-assets/binding/#binding`
		);
	}

	// the user might have forgot the `main` key or should remove the `assets.binding`
	// key to deploy static assets without a Worker
	if (!wrangler_config.main && wrangler_config.assets?.binding) {
		throw new Error(
			`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.`
		);
	}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Add `"assets": { "directory": "<built-client-path>" }` to wrangler.jsonc (typically the adapter writes this — ensure you aren't overwriting it).
  2. Fix typos: the key must be exactly `assets.directory`, not nested differently.
  3. If you have no `main` and no custom assets config, remove the partial `assets`/`main` keys and let the adapter configure them.
  4. Re-run `vite build` after editing so the adapter can regenerate/validate the config.

Example fix

// before
{
  "main": "src/worker.js",
  "assets": { "binding": "ASSETS" }
}

// after
{
  "main": "src/worker.js",
  "assets": { "directory": ".svelte-kit/cloudflare", "binding": "ASSETS" }
}
Defensive patterns

Strategy: validation

Validate before calling

if ((cfg.main || cfg.assets) && !cfg.assets?.directory) {
  throw new Error('wrangler config needs assets.directory when main or assets is set');
}

Type guard

function hasAssetsDirectory(config) {
  return typeof config?.assets?.directory === 'string' && config.assets.directory.length > 0;
}

Try / catch

try {
  await build();
} catch (e) {
  if (String(e).includes('`assets.directory`')) {
    console.error('Add assets.directory to wrangler config');
    process.exit(1);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Hand-editing wrangler.jsonc and adding `assets.binding` but forgetting `directory`; typos like `asset.directory`; partial migration from `site` to `assets`.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/125ac97847388f96. Report an issue: GitHub.