sveltejs/kit · error · Error
${keypath} must be a valid origin (e.g. 'https://my-site.com
Error message
${keypath} must be a valid origin (e.g. 'https://my-site.com'). '${input}' could not be parsed as a URL What it means
`prerender.origin` (validated here) must be a parseable URL, since SvelteKit uses it to resolve absolute URLs during prerendering. If `new URL(input)` throws, the config value is not a valid URL and this error is thrown including the bad input.
Source
Thrown at packages/kit/src/core/config/options.js:225
if (input.endsWith('/')) {
throw new Error(
`${keypath} option must not end with '/'. See https://svelte.dev/docs/kit/configuration#paths`
);
}
}
return input;
}),
origin: validate(undefined, (input, keypath) => {
assert_string(input, keypath);
let url;
try {
url = new URL(input);
} catch {
throw new Error(
`${keypath} must be a valid origin (e.g. 'https://my-site.com'). '${input}' could not be parsed as a URL`
);
}
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new Error(
`${keypath} must be a valid origin — only 'http' and 'https' protocols are supported, received '${url.protocol}'`
);
}
const origin = url.origin;
if (input !== origin) {
throw new Error(
`${keypath} must be a valid origin — received '${input}' which contains a path, query, or hash. Use the bare origin '${origin}' instead`
);
}
View on GitHub (pinned to 03f1687fe6)
Solutions
- Include the full scheme: `https://my-site.com`
- Verify with `new URL(value)` in Node before assigning
- If the value comes from an env var, check it is set and non-empty: `origin: process.env.ORIGIN ?? 'https://my-site.com'`
- Trim whitespace from env-derived values
Example fix
// before
prerender: { origin: 'my-site.com' }
// after
prerender: { origin: 'https://my-site.com' } Defensive patterns
Strategy: validation
Validate before calling
const origin = config.prerender?.origin;
if (origin !== undefined) {
try {
new URL(origin);
} catch {
throw new Error(`prerender.origin is not a valid URL: '${origin}'`);
}
} Type guard
function isParseableUrl(v) {
if (typeof v !== 'string') return false;
try {
new URL(v);
return true;
} catch {
return false;
}
} Try / catch
try {
assertOrigin(config.prerender?.origin);
} catch (e) {
if (String(e.message).includes('could not be parsed as a URL')) {
console.error('Include the full scheme, e.g. https://my-site.com');
}
throw e;
} Prevention
- Always write origins with scheme and host: `https://example.com`
- Guard env-derived origins with a default: `process.env.ORIGIN ?? 'https://example.com'`
- Trim and validate env vars in CI before they reach svelte.config.js
When it happens
Trigger: `prerender: { origin: 'my-site.com' }` (missing scheme) or `origin: 'https'`/`origin: ''` — any string the `URL` constructor cannot parse.
Common situations: Forgetting `https://` in svelte.config.js; env var `ORIGIN` unset so an empty or partial string is used; trailing whitespace or typos in CI-configured origins.
Understand the failure class
Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.
Related errors
- ${keypath} should be "fail", "warn", "ignore" or a custom fu
- ${keypath} option must be an absolute path, if specified. Se
- ${keypath} must be a valid origin — only 'http' and 'https'
- Invalid isr.expiration value: ${JSON.stringify(value)} (${de
- The SvelteKit options from the Vite config must be an object
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/cc283dc2cee74732.
Report an issue: GitHub.