sveltejs/kit · error · Error
${keypath} must be a valid origin — only 'http' and 'https'
Error message
${keypath} must be a valid origin — only 'http' and 'https' protocols are supported, received '${url.protocol}' What it means
Beyond parseability, the origin must use the `http:` or `https:` protocol. SvelteKit prerenders real HTTP pages, so schemes like `ftp:`, `file:`, `ws:` or custom app schemes are rejected, with the offending protocol included in the message.
Source
Thrown at packages/kit/src/core/config/options.js:231
}
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`
);
}
return origin;
}),
relative: boolean(true)
}),
preprocess: any(),View on GitHub (pinned to 03f1687fe6)
Solutions
- Switch to `https://` (or `http://` for local testing): `https://my-site.com`
- If you need local prerendering, use `http://localhost` or `http://sveltekit-prerender` as appropriate
- Validate the protocol before assigning: `['http:', 'https:'].includes(new URL(v).protocol)`
Example fix
// before
prerender: { origin: 'file:///srv/site' }
// after
prerender: { origin: 'https://my-site.com' } Defensive patterns
Strategy: validation
Validate before calling
const origin = config.prerender?.origin;
if (origin !== undefined) {
const protocol = new URL(origin).protocol;
if (protocol !== 'http:' && protocol !== 'https:') {
throw new Error(`prerender.origin must use http/https, got ${protocol}`);
}
} Type guard
function isHttpOrigin(v) {
try {
const p = new URL(v).protocol;
return p === 'http:' || p === 'https:';
} catch {
return false;
}
} Try / catch
try {
assertHttpOrigin(config.prerender?.origin);
} catch (e) {
if (String(e.message).includes("only 'http' and 'https' protocols")) {
console.error('Replace the scheme with https:// (or http:// for local testing)');
}
throw e;
} Prevention
- Only use `http://` or `https://` schemes in prerender.origin
- Use `http://localhost` or `http://sveltekit-prerender` for local prerender testing, never `file://`
- Add a pre-build config check asserting the origin protocol
When it happens
Trigger: `prerender: { origin: 'ftp://my-site.com' }`, `origin: 'file:///path'`, or a custom scheme like `app://host` — anything where `url.protocol` is neither `http:` nor `https:`.
Common situations: Pasting a local file URL during local testing; using a websocket or app-deep-link scheme by mistake; npm package URLs (`package://`) pasted into config.
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} must be a valid origin (e.g. 'https://my-site.com
- ${keypath} should be "fail", "warn", "ignore" or a custom fu
- ${keypath} option must be an absolute path, if specified. Se
- ${keypath} option must not end with '/'. See https://svelte.
- To suppress or handle this error, implement `${name}` in htt
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/f9125f7e36e0b5ef.
Report an issue: GitHub.