Skip to main content

#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 $lib and was automatically configured by SvelteKit. It is now #lib and must be declared in your package.json imports field. import { foo } from '$lib/foo.js' becomes import { foo } from '#lib/foo.js'.

src/lib/Component
A reusable component
src/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