sveltejs/kit · error · Error
`$lib` has been removed. Use `#lib` instead: https://svelte.
Error message
`$lib` has been removed. Use `#lib` instead: https://svelte.dev/docs/kit/$lib. To keep using `$lib`, add `alias: { '$lib': 'src/lib' }` to your SvelteKit config. What it means
Vite resolveId hook guard in the SvelteKit plugin: an import matched the removed $lib alias pattern and failed to resolve any other way. $lib was replaced by the #lib alias; the error explains the removal, links the migration docs, and offers the escape hatch of re-adding $lib manually via the alias config.
Source
Thrown at packages/kit/src/exports/vite/index.js:320
options: svelte_config
},
resolveId: {
filter: { id: removed_modules.map(({ pattern }) => pattern) },
async handler(id, importer, options) {
const resolved = await this.resolve(id, importer, { ...options, skipSelf: true });
if (resolved) return resolved;
const aliases = svelte_config.alias;
for (const { name, pattern, message } of removed_modules) {
if (!pattern.test(id)) continue;
// If the user re-added an alias for this module (as the migration message
// suggests), a failed resolution means a genuine missing file rather than
// use of the removed module. Let Vite report the real "not found" error
// instead of the misleading migration message.
if (name in aliases || `${name}/*` in aliases) return;
throw stackless(message);
}
}
},
/**
* Build the SvelteKit-provided Vite config to be merged with the user's vite.config.js file.
* @see https://vitejs.dev/guide/api-plugin.html#config
*/
config: {
order: 'pre',
handler(config, config_env) {
initial_config = config;
is_build = config_env.command === 'build';
kit = process_config(svelte_config, root);
out_dir = posixify(kit.outDir);
out = `${out_dir}/output`;
View on GitHub (pinned to 03f1687fe6)
Solutions
- Replace $lib imports with #lib, e.g. `import x from '#lib/x'`
- Add `alias: { '$lib': 'src/lib' }` to the SvelteKit config to keep using $lib temporarily
- Run the migration to bulk-rewrite $lib imports
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/kit/src/exports/vite/index.js:320 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/efae7dcfdbc6b562.
Report an issue: GitHub.