sveltejs/kit · error · Error

${keypath} option must be an absolute path, if specified. Se

Error message

${keypath} option must be an absolute path, if specified. See https://svelte.dev/docs/kit/configuration#paths

What it means

`paths.assets` specifies where static assets are served from and, if set, must be an absolute URL (matching `/^[a-z]+:\/\//`, i.e. a scheme like `https://`). Relative paths or bare hostnames are rejected because asset URLs must resolve independently of `paths.base`.

Source

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

	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(
						`${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;

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Prefix the value with its scheme: `https://cdn.example.com`
  2. Leave `assets` as `''` (default) to serve assets from the same origin — usually what you want
  3. Validate with `new URL(value)` before assigning to confirm it parses

Example fix

// before
paths: { assets: 'cdn.example.com' }
// after
paths: { assets: 'https://cdn.example.com' }
Defensive patterns

Strategy: validation

Validate before calling

const assets = config.paths?.assets;
if (assets && !/^[a-z]+:\/\//.test(assets)) {
  throw new Error(`paths.assets must be an absolute URL with a scheme, got: ${assets}`);
}

Type guard

function isAbsoluteAssetUrl(v) {
  return v === undefined || v === '' || (typeof v === 'string' && /^[a-z]+:\/\//.test(v));
}

Try / catch

try {
  assertAssetsUrl(config.paths?.assets);
} catch (e) {
  if (String(e.message).includes('must be an absolute path, if specified')) {
    console.error('Prefix assets with its scheme, e.g. https://cdn.example.com');
  }
  throw e;
}

Prevention

When it happens

Trigger: `paths.assets: 'cdn.example.com'` (no scheme), `paths.assets: '/static'` (relative path), or any value lacking a `scheme://` prefix.

Common situations: Using an external CDN and forgetting the `https://` prefix; assuming assets behaves like `base` (root-relative); typos like `http:/cdn...` with a single slash.

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


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