sveltejs/kit · error · Error

${keypath} option must not end with '/'. See https://svelte.

Error message

${keypath} option must not end with '/'. See https://svelte.dev/docs/kit/configuration#paths

What it means

When `paths.assets` is set to an absolute URL it must not end with `/`. SvelteKit joins asset paths itself, and a trailing slash would produce double-slash URLs like `https://cdn.example.com//_app/...`.

Source

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

				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;

			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`
				);

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Remove the trailing slash: `https://cdn.example.com`
  2. Normalize at config load: `assets.replace(/\/$/, '')`
  3. Verify generated asset URLs in the built output no longer contain `//`

Example fix

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

Strategy: validation

Validate before calling

const assets = config.paths?.assets;
if (typeof assets === 'string' && assets.endsWith('/')) {
  throw new Error('paths.assets must not end with "/"');
}

Type guard

function hasNoTrailingSlash(v) {
  return v === undefined || v === '' || (typeof v === 'string' && !v.endsWith('/'));
}

Try / catch

try {
  assertNoTrailingSlash(config.paths?.assets);
} catch (e) {
  if (String(e.message).includes("must not end with '/'")) {
    console.error('Strip the trailing slash from the CDN origin');
  }
  throw e;
}

Prevention

When it happens

Trigger: `paths.assets: 'https://cdn.example.com/'` — any absolute URL with a trailing slash.

Common situations: Copying the CDN base URL straight from a browser address bar; CDN dashboards showing origins with trailing slashes.

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/18692f54f6f38a99. Report an issue: GitHub.