sveltejs/kit · error · Error

${keypath} should be one of "${options}" or "${options[optio

Error message

${keypath} should be one of "${options}" or "${options[options.length - 1]}"

What it means

SvelteKit's config validator calls `list()` to check that a config option equals one of a fixed set of allowed values. When the value is not in the list, it throws a message enumerating every valid choice. This guards against typos and unsupported option values in svelte.config.js.

Source

Thrown at packages/kit/src/core/config/options.js:487

			throw new Error(`${keypath} should be true or false, if specified`);
		}
		return input;
	});
}

/**
 * @param {string[]} options
 * @returns {Validator}
 */
function list(options, fallback = options[0]) {
	return validate(fallback, (input, keypath) => {
		if (!options.includes(input)) {
			// prettier-ignore
			const msg = options.length > 2
				? `${keypath} should be one of ${options.slice(0, -1).map(input => `"${input}"`).join(', ')} or "${options[options.length - 1]}"`
				: `${keypath} should be either "${options[0]}" or "${options[1]}"`;

			throw new Error(msg);
		}
		return input;
	});
}

/**
 * @param {(...args: any) => any} fallback
 * @returns {Validator}
 */
function fun(fallback) {
	return validate(fallback, (input, keypath) => {
		if (typeof input !== 'function') {
			throw new Error(`${keypath} should be a function, if specified`);
		}
		return input;
	});
}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Read the error message: it lists exactly the accepted values in quotes.
  2. Replace the option value with one of the listed allowed values in svelte.config.js.
  3. If migrating from an older SvelteKit version, check the changelog/docs for renamed option values.

Example fix

// before (svelte.config.js)
kit: { router: { type: 'hash-router' } }
// after
kit: { router: { type: 'hash' } }
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED_ROUTER_TYPES = ['pathname', 'hash'];
const cfg = kit?.router?.type;
if (cfg !== undefined && !ALLOWED_ROUTER_TYPES.includes(cfg)) {
  throw new Error(`router.type must be one of ${ALLOWED_ROUTER_TYPES.join(', ')}, got: ${cfg}`);
}

Type guard

function isRouterType(v) {
  return v === 'pathname' || v === 'hash';
}

Try / catch

try {
  await dev({ config });
} catch (e) {
  if (String(e.message).includes('should be one of')) {
    console.error('Invalid config option value:', e.message);
  } else throw e;
}

Prevention

When it happens

Trigger: Setting a svelte.config.js option whose validator is `list(...)` to a value outside the allowed set — e.g. `router: { type: 'hash-router' }` instead of 'hash' or 'pathname', or `csr: 'true'` (string) where only booleans are expected via list.

Common situations: Typo in option value; copying config from an outdated tutorial or older SvelteKit version where a value was renamed; quoting/typing mistakes like string 'true' instead of boolean true.

Related errors


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