sveltejs/kit · error · Error

The SvelteKit options from the Vite config must be an object

Error message

The SvelteKit options from the Vite config must be an object. See https://svelte.dev/docs/kit/configuration

What it means

validate_config receives the `kit` (SvelteKit options) section exported from the Vite config. If that value is not an object (e.g. undefined, a string, or a function), validation cannot proceed, so it throws with a pointer to the configuration docs. This typically happens when svelte.config.js fails to export the config correctly or the Vite plugin receives malformed options.

Source

Thrown at packages/kit/src/core/config/index.js:173

			config.files.hooks.server = path.resolve(cwd, config.files.hooks.server);
			config.files.hooks.universal = path.resolve(cwd, config.files.hooks.universal);
		} else if (key !== 'lib' /* TODO remove when we remove the `lib` option altogether */) {
			// @ts-expect-error
			config.files[key] = path.resolve(cwd, config.files[key]);
		}
	}

	return config;
}

/**
 * @param {Config} config
 * @returns {ValidatedConfig}
 */
export function validate_config(config) {
	try {
		if (typeof config !== 'object') {
			throw new Error(
				'The SvelteKit options from the Vite config must be an object. See https://svelte.dev/docs/kit/configuration'
			);
		}

		const validated = validate_options(config, 'config');
		const files = validated.files;

		files.hooks.client ??= path.join(files.src, 'hooks.client');
		files.hooks.server ??= path.join(files.src, 'hooks.server');
		files.hooks.universal ??= path.join(files.src, 'hooks');
		files.params ??= path.join(files.src, 'params');
		files.routes ??= path.join(files.src, 'routes');
		files.serviceWorker ??= path.join(files.src, 'service-worker');
		files.appTemplate ??= path.join(files.src, 'app.html');
		files.errorTemplate ??= path.join(files.src, 'error.html');

		if (validated.router.resolution === 'server') {
			if (validated.router.type === 'hash') {

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Ensure svelte.config.js exports the object as default: `export default { kit: {...} }` (or `module.exports = {...}`).
  2. If using ESM/CJS interop in a custom loader, read `.default` from the imported module.
  3. Check that the Vite plugin invocation receives the kit options object, not a string or function.

Example fix

// before: svelte.config.js missing export
const config = { kit: { adapter: adapter() } };
// after
const config = { kit: { adapter: adapter() } };
export default config;
Defensive patterns

Strategy: type-guard

Validate before calling

const mod = await import('./svelte.config.js');
const config = mod.default ?? mod;
if (typeof config !== 'object' || config === null) {
  throw new Error('svelte.config.js must default-export an object');
}

Type guard

/** @returns {config is Record<string, unknown>} */
function isKitConfig(value) {
  return typeof value === 'object' && value !== null;
}

Try / catch

try {
  const cfg = (await import('./svelte.config.js')).default;
} catch (e) {
  if (e.message.includes('must be an object')) {
    console.error('Check svelte.config.js: missing `export default config`?');
  }
  throw e;
}

Prevention

When it happens

Trigger: validate_config is called (via extract_svelte_config / validate_paths) with a `config` argument whose typeof is not 'object' — commonly `undefined` because svelte.config.js has no default export, or the loaded module resolved to a non-object value.

Common situations: Forgetting `export default config` in svelte.config.js; a typo like `export defualt`; importing the config file from a CJS/ESM mismatch so the interop yields undefined; passing the config object inside a wrapper instead of directly.

Related errors


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