sveltejs/kit · error · Error
${keypath} option must either be the empty string or a root-
Error message
${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://svelte.dev/docs/kit/configuration#paths What it means
`paths.base` must be either the empty string or a root-relative path that starts with `/` but does not end with `/`. SvelteKit enforces this so URLs are composed unambiguously. `assert_string` also guarantees it is a string first.
Source
Thrown at packages/kit/src/core/config/options.js:191
);
}),
outDir: string('.svelte-kit'),
output: object({
linkHeaderPreload: boolean(false),
preloadStrategy: removed(
(keypath) => `\`${keypath}\` has been removed. modulepreload will always be used`
),
bundleStrategy: list(['split', 'single', 'inline'])
}),
paths: object({
base: validate('', (input, keypath) => {
assert_string(input, keypath);
if (input !== '' && (input.endsWith('/') || !input.startsWith('/'))) {
throw new Error(
`${keypath} option must either be the empty string or a root-relative path that starts but doesn't end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
);
}
return input;
}),
assets: validate('', (input, keypath) => {
assert_string(input, keypath);
if (input) {
if (!/^[a-z]+:\/\//.test(input)) {
throw new Error(
`${keypath} option must be an absolute path, if specified. See https://svelte.dev/docs/kit/configuration#paths`
);
}
if (input.endsWith('/')) {
throw new Error(View on GitHub (pinned to 03f1687fe6)
Solutions
- Use `''` (empty string) if the app is served from the domain root
- Otherwise use a path starting with `/` and not ending with `/`: `/my-app`
- Normalize env-derived values: `base.replace(/\/$/, '')` and ensure a leading `/`
Example fix
// before
paths: { base: 'my-app/' }
// after
paths: { base: '/my-app' } Defensive patterns
Strategy: validation
Validate before calling
const base = config.paths?.base;
if (base !== undefined && base !== '' && (!base.startsWith('/') || base.endsWith('/'))) {
throw new Error('paths.base must be "" or start with "/" and not end with "/"');
} Type guard
function isValidBasePath(v) {
return v === undefined || v === '' || (typeof v === 'string' && v.startsWith('/') && !v.endsWith('/'));
} Try / catch
try {
assertBasePath(config.paths?.base);
} catch (e) {
if (String(e.message).includes("paths.base option must either be the empty string")) {
console.error('Use "" or a path like /my-app (no trailing slash)');
}
throw e;
} Prevention
- Normalize env-derived base paths: strip trailing `/`, ensure leading `/`
- Prefer omitting `base` entirely when serving from the domain root
- Test deploys to subpaths locally with `vite preview` before shipping
When it happens
Trigger: `paths.base: 'app'` (no leading slash), `paths.base: '/app/'` (trailing slash), or a non-string value that passes string assertion only when it is a string but malformed.
Common situations: Deploying under a subpath and writing the subpath without a leading slash; copying GitHub Pages examples with trailing slashes; env vars like `BASE_PATH=app/` with trailing slash.
Related errors
- ${keypath} option must be an absolute path, if specified. Se
- 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
- The SvelteKit Vite plugin ${keypath} should be an object wit
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/90900a1d407cd00a.
Report an issue: GitHub.