sveltejs/kit · error · Error
${keypath} should be a string, if specified
Error message
${keypath} should be a string, if specified What it means
`assert_string` verifies that a config option expected to be a string is actually a string. SvelteKit throws this when a string-typed option (like an adapter name, paths option, or env dir) receives a number, boolean, object, or undefined-that-isn't-absent.
Source
Thrown at packages/kit/src/core/config/options.js:516
return validate(fallback, (input, keypath) => {
if (typeof input !== 'function') {
throw new Error(`${keypath} should be a function, if specified`);
}
return input;
});
}
function any() {
return validate(undefined, (input) => input);
}
/**
* @param {string} input
* @param {string} keypath
*/
function assert_string(input, keypath) {
if (typeof input !== 'string') {
throw new Error(`${keypath} should be a string, if specified`);
}
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Check the option named in the keypath in svelte.config.js.
- Convert the value to a string (add quotes) or supply the correct string value.
- For path-like options, ensure you didn't paste a URL or number where a path is required.
Example fix
// before
paths: { base: 3000 }
// after
paths: { base: '/app' } Defensive patterns
Strategy: validation
Validate before calling
const stringOptions = [['paths', 'base'], ['paths', 'assets']];
for (const [a, b] of stringOptions) {
const v = config?.kit?.[a]?.[b];
if (v !== undefined && typeof v !== 'string') {
throw new Error(`${a}.${b} must be a string, got ${typeof v}`);
}
} Type guard
function isString(v) {
return typeof v === 'string';
} Try / catch
try {
await build(config);
} catch (e) {
if (String(e.message).includes('should be a string')) {
console.error('String config option got a non-string value:', e.message);
} else throw e;
} Prevention
- Quote all path-like and name-like config values in svelte.config.js.
- Rely on the generated Config type / editor type checking to catch wrong types.
- After converting config from JSON/YAML, verify values kept their intended types.
When it happens
Trigger: Setting a string config option to a non-string, e.g. `paths: { base: 3000 }`, `outDir: true`, or passing a number where an appDir string is required.
Common situations: Copying config from docs with placeholder values not replaced; using a numeric port where a string path is expected; YAML/JSON-style config mistakes after converting to JS.
Related errors
- 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
- ${keypath} should be an object
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/32d0308db4aaf146.
Report an issue: GitHub.