sveltejs/kit · error · Error
${keypath} cannot be empty
Error message
${keypath} cannot be empty What it means
SvelteKit validates certain config values (like `paths.base`) must be non-empty strings. When a value that must be a non-empty string is set to an empty string, validation throws with the config key path (keypath) in the message. It exists to catch misconfigured route/path options early before build.
Source
Thrown at packages/kit/src/core/config/options.js:81
}
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(
`${keypath} cannot start or end with '/'. See https://svelte.dev/docs/kit/configuration`
);
}
} else {
throw new Error(`${keypath} cannot be empty`);
}
return input;
}),
compilerOptions: any(),
csp: object({
mode: list(['auto', 'hash', 'nonce']),
directives,
reportOnly: directives
}),
csrf: object({
checkOrigin: removed(
(keypath) => `\`${keypath}\` has been removed in favour of \`csrf.trustedOrigins\``
),
trustedOrigins: string_array([])View on GitHub (pinned to 03f1687fe6)
Solutions
- Set the option to a non-empty string value appropriate for the option
- Remove the key entirely so SvelteKit uses its built-in default instead of an empty string
- If the value comes from an env var, provide a fallback: `process.env.MY_VAR || '/default'`
Example fix
// before
export default {
paths: { base: '' }
};
// after
export default {
paths: { base: '/my-app' }
}; Defensive patterns
Strategy: validation
Validate before calling
const value = config.paths?.base;
if (value !== undefined && (typeof value !== 'string' || value === '')) {
throw new Error('paths.base must be a non-empty string (or omitted)');
} Type guard
function isValidBase(v) {
return v === undefined || (typeof v === 'string' && v !== '');
} Try / catch
try {
validateConfig(config);
} catch (e) {
if (String(e.message).includes('cannot be empty')) {
console.error('Fix empty config value in svelte.config.js');
}
throw e;
} Prevention
- Never hardcode empty strings for required config options — omit the key to use defaults
- Provide fallbacks when reading env vars: `process.env.X || 'default'`
- Run `vite dev` or `vite build` locally before CI to surface config validation early
When it happens
Trigger: Setting a config option validated by the empty-string guard (e.g. `paths.base: ''` is fine, but keys whose value must be non-empty) to `''` — specifically any string-validated keypath that is tested for emptiness and receives `''`.
Common situations: Copying example configs with placeholder empty values; env-driven config where an env var is unset and defaults to empty string; accidentally deleting the value in svelte.config.js.
Understand the failure class
Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.
Related errors
- Each member of ${keypath} must start with '.' — saw '${exten
- ${keypath} should be one of "${options}" or "${options[optio
- Invalid isr.expiration value: ${JSON.stringify(value)} (${de
- The SvelteKit options from the Vite config must be an object
- ${keypath} should be "fail", "warn", "ignore" or a custom fu
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/3068fd56d0f81e05.
Report an issue: GitHub.