sveltejs/kit · warning

`asset('${path}')` should now be `asset('${path.slice(1)}')`

Error message

`asset('${path}')` should now be `asset('${path.slice(1)}')`

What it means

In SvelteKit 2.x the `asset()` helper from `$app/paths` expects a path relative to the assets directory, without a leading slash. Passing `/logo.png` triggers a DEV-mode warning and the leading slash is stripped automatically; the behaviour will be removed in 4.0.

Source

Thrown at packages/kit/src/runtime/app/paths/client.js:33

 * ```svelte
 * <script>
 * 	import { asset } from '$app/paths';
 * </script>
 *
 * <img alt="a potato" src={asset('potato.jpg')} />
 * ```
 * @since 2.26
 *
 * @param {AssetPath} file
 * @returns {string}
 */
export function asset(file) {
	let path = /** @type {string} */ (file);

	// TODO 4.0 remove this
	if (path[0] === '/') {
		if (DEV) {
			console.warn(`\`asset('${path}')\` should now be \`asset('${path.slice(1)}')\``);
		}

		path = path.slice(1);
	}

	return (assets || base) + '/' + path;
}

const pathname_prefix = hash_routing ? '#' : '';

/**
 * Resolve a pathname by prefixing it with the base path, if any, or resolve a route ID by populating dynamic segments with parameters.
 *
 * During server rendering, the base path is relative and depends on the page currently being rendered.
 *
 * @example
 * ```js
 * import { resolve } from '$app/paths';

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Remove the leading slash: call `asset('foo.png')` instead of `asset('/foo.png')`
  2. Search the codebase for `asset('` with a leading slash inside the argument and fix each occurrence

Example fix

// before
const url = asset('/images/logo.png');
// after
const url = asset('images/logo.png');
Defensive patterns

Strategy: validation

Validate before calling

function safeAsset(path) { return asset(path.startsWith('/') ? path.slice(1) : path); }

Type guard

function hasLeadingSlash(p) { return typeof p === 'string' && p.startsWith('/'); }

Prevention

When it happens

Trigger: Calling `asset('/foo.png')` (file starting with '/') from client-side code in DEV; the client `asset()` in packages/kit/src/runtime/app/paths/client.js detects `path[0] === '/'` and warns.

Common situations: Migrating from SvelteKit 1.x where `asset()` took absolute paths; copy-pasted static asset references like `asset('/favicon.ico')` in components.

Related errors


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