sveltejs/kit · error · Error

${keypath} must be a valid origin — received '${input}' whic

Error message

${keypath} must be a valid origin — received '${input}' which contains a path, query, or hash. Use the bare origin '${origin}' instead

What it means

SvelteKit validates `kit.prerender.origin` (or other origin options) by parsing the supplied value as a URL and comparing it to the URL's origin part. If the configured value includes a path, query string, or hash — i.e. it is not a bare origin — the validator throws this error and suggests the correct bare origin to use.

Source

Thrown at packages/kit/src/core/config/options.js:239

			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(),

	prerender: object({
		concurrency: number(1),
		crawl: boolean(true),
		entries: validate(['*'], (input, keypath) => {
			if (!Array.isArray(input) || !input.every((page) => typeof page === 'string')) {
				throw new Error(`${keypath} must be an array of strings`);
			}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Replace the configured value with only the origin portion (scheme + host + port), e.g. 'https://example.com' — the error message tells you the exact bare origin to use.
  2. If your site is served from a sub-path, keep the origin bare and configure the sub-path via `paths.base` instead.
  3. Re-run the build/dev command to confirm config validation passes.

Example fix

// before
const config = {
  kit: { prerender: { origin: 'https://example.com/docs' } }
};
// after
const config = {
  kit: { prerender: { origin: 'https://example.com' } }
};
Defensive patterns

Strategy: validation

Validate before calling

function isBareOrigin(value) {
  try {
    const url = new URL(value);
    return url.origin === value;
  } catch {
    return false;
  }
}
if (!isBareOrigin(cfg.kit?.prerender?.origin)) throw new Error('prerender.origin must be a bare origin');

Type guard

function isBareOrigin(v) { try { return typeof v === 'string' && new URL(v).origin === v; } catch { return false; } }

Try / catch

try {
  build({ config: cfg });
} catch (e) {
  if (String(e.message).includes('must be a valid origin')) {
    cfg.kit.prerender.origin = new URL(cfg.kit.prerender.origin).origin; // auto-strip
  } else throw e;
}

Prevention

When it happens

Trigger: Setting `kit.prerender.origin` to a full URL with a path or query, e.g. 'https://example.com/app' or 'https://example.com/?x=1', then running a build or `vite dev` where config is validated via validate_config/options.

Common situations: Copying a full site URL (including a deployed app sub-path or a URL with utm/hash fragments) from the browser address bar into svelte.config.js instead of stripping it down to scheme + host + port.

Related errors


AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02). Data as JSON: /api/errors/c642a286d216b73d. Report an issue: GitHub.