sveltejs/kit · warning

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

Error message

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

What it means

Server-side twin of the client warning: the SSR version of `asset()` from `$app/paths` now expects paths without a leading slash. A leading slash is stripped with a DEV warning; in future versions it will stop being tolerated.

Source

Thrown at packages/kit/src/runtime/app/paths/server.js:17

import { base, assets, relative } from './internal/server.js';
import { resolve_route, find_route } from '../../../utils/routing.js';
import { decode_pathname } from '../../../utils/url.js';
import { add_data_suffix } from '../../../pathname.js';
import { try_get_request_store } from '@sveltejs/kit/internal/server';
import { manifest } from '../../server/internal.js';
import { get_hooks } from '<sveltekit:generated>/server.js';
import { DEV } from 'esm-env';

export { base, assets, app_dir } from './internal/server.js';

/** @type {typeof import('./client.js').asset} */
export function asset(file) {
	// TODO 4.0 remove this
	if (file[0] === '/') {
		if (DEV) {
			console.warn(`\`asset('${file}')\` should now be \`asset('${file.slice(1)}')\``);
		}

		file = file.slice(1);
	}

	return assets !== base ? `${assets}/${file}` : resolve(file);
}

/** @type {typeof import('./client.js').resolve} */
export function resolve(id, params) {
	let resolved;

	if (id[0] === '/') {
		// route ID
		if (id.includes('[') && !params) {
			throw new Error(`Missing params for dynamic route ID ${id}`);
		}

View on GitHub (pinned to 03f1687fe6)

Solutions

  1. Drop the leading slash from the argument: `asset('file.css')`
  2. Fix shared modules so both SSR and client paths use the slash-less form

Example fix

// before
const href = asset('/styles/app.css');
// after
const href = asset('styles/app.css');
Defensive patterns

Strategy: validation

Validate before calling

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

Type guard

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

Prevention

When it happens

Trigger: Calling `asset('/file.css')` in code that runs during server-side rendering (or prerendering); the server `asset()` in packages/kit/src/runtime/app/paths/server.js warns when `file[0] === '/'`.

Common situations: Shared components/templates rendering asset URLs during SSR after upgrading from SvelteKit 1.x; email/HTML templates that embed `asset('/...')` links.

Related errors


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