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
- Change alias to an object form: `{ alias: { $lib: 'src/lib' } }`.
- If you need advanced Vite alias semantics, configure them in vite.config's resolve.alias instead of kit.alias.
- 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
- Use object syntax for kit.alias, not arrays or strings
- Put advanced aliasing (regex, arrays) in vite.config resolve.alias instead
- Ensure every alias value is a plain string path
- Type the config with the exported Config type to catch this at edit time
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
- The SvelteKit options from the Vite config must be an object
- Invalid isr.expiration value: ${JSON.stringify(value)} (${de
- ${keypath} should be "fail", "warn", "ignore" or a custom fu
- The SvelteKit Vite plugin ${keypath} should be an object wit
- ${keypath} cannot start or end with '/'. See https://svelte.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/17cf18328d5176e2.
Report an issue: GitHub.