sveltejs/kit · error · Error

${keypath} should be an object

Error message

${keypath} should be an object

What it means

`kit.alias` must be a plain object mapping import aliases to file paths, where every value is a string. The validator throws the generic "should be an object" message when the value itself is not an object (string, array, function, etc.), and each entry's value is separately checked with assert_string.

Source

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

	if (typeof input === 'function') return input;
	if (['fail', 'warn', 'ignore'].includes(input)) return input;
	throw new Error(`${keypath} should be "fail", "warn", "ignore" or a custom function`);
});

const options = {
	adapter: validate(undefined, (input, keypath) => {
		if (typeof input !== 'object' || !input.adapt) {
			const message = `The SvelteKit Vite plugin ${keypath} should be an object with an \`adapt\` method`;
			throw new Error(`${message}. See https://svelte.dev/docs/kit/adapters`);
		}

		return input;
	}),

	alias: deprecate(
		validate({}, (input, keypath) => {
			if (typeof input !== 'object') {
				throw new Error(`${keypath} should be an object`);
			}

			for (const key in input) {
				assert_string(input[key], `${keypath}.${key}`);
			}

			return input;
		}),
		(keypath) =>
			`The \`${keypath}\` option is deprecated, and will be removed in a future version of SvelteKit. Use subpath imports instead: https://svelte.dev/docs/kit/$lib`
	),

	appDir: validate('_app', (input, keypath) => {
		assert_string(input, keypath);

		if (input) {
			if (input.startsWith('/') || input.endsWith('/')) {
				throw new Error(

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Change alias to an object form: `{ alias: { $lib: 'src/lib' } }`.
  2. If you need advanced Vite alias semantics, configure them in vite.config's resolve.alias instead of kit.alias.
  3. Ensure every alias value is a string path.

Example fix

// before
kit: { alias: ['@components:src/lib/components'] }
// after
kit: { alias: { '@components': 'src/lib/components' } }
Defensive patterns

Strategy: type-guard

Validate before calling

const alias = config.kit?.alias;
if (alias !== undefined && (typeof alias !== 'object' || Array.isArray(alias))) {
  throw new Error('kit.alias must be a plain object of string paths');
}

Type guard

/** @returns {alias is Record<string, string>} */
function isAliasMap(alias) {
  return typeof alias === 'object' && alias !== null && !Array.isArray(alias) &&
    Object.values(alias).every((v) => typeof v === 'string');
}

Try / catch

try {
  await viteBuild();
} catch (e) {
  if (e.message.includes('should be an object')) {
    console.error('kit.alias must be an object like { $lib: "src/lib" }');
  }
  throw e;
}

Prevention

When it happens

Trigger: validate_options validates config.kit.alias and typeof input !== 'object' — e.g. `alias: '~/src'` (string) or `alias: ['~/lib']` (array).

Common situations: Confusing kit.alias with Vite's resolve.alias syntax; copying an array-style alias list from another tool (webpack loaders, tsconfig paths pasted as array); accidentally assigning the alias map at the wrong key.

Related errors


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