#lib
When scaffolding a new SvelteKit project through the sv CLI, it automatically creates a #lib import alias for your src/lib directory, by adding the following to your package.json:
{
"imports": {
"#lib": "./src/lib/index.js",
"#lib/*": "./src/lib/*"
}
}The # prefix leverages Node's built-in subpath imports feature, which reserves # for package-internal aliases. Vite and TypeScript both resolve these natively.
Legacy mode
Previously, this alias was
$liband was automatically configured by SvelteKit. It is now#liband must be declared in yourpackage.jsonimportsfield.import { foo } from '$lib/foo.js'becomesimport { foo } from '#lib/foo.js'.
src/lib/Component
A reusable componentsrc/routes/+page
<script>
import Component from '#lib/Component.svelte';
</script>
<Component /><script lang="ts">
import Component from '#lib/Component.svelte';
</script>
<Component />Edit this page on GitHub llms.txt
previous next