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
- Remove the leading slash: call `asset('foo.png')` instead of `asset('/foo.png')`
- 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
- Never pass absolute paths to `asset()`
- Centralize asset URL building in one helper
- Grep for `asset('/` during upgrades
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
- `asset('${file}')` should now be `asset('${file.slice(1)}')`
- read(...) failed: could not fetch ${url} (${response.status}
- Could not locate ${file_path}. Please move it to be located
- Could not locate ${file_path}. See https://vitejs.dev/guide/
- ${keypath} option must either be the empty string or a root-
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/3f06f4dae87b63a0.
Report an issue: GitHub.