Posts tagged "Sveltekit"
-
SvelteKit 3 is out today, and it just works on Netlify on day one. To upgrade, run:
npx sv migrate sveltekit-3The migration tool handles most of the mechanical changes for you, including moving your config and updating imports. You can also check out the official migration guide.
What’s new
Some highlights include:
- Vite 8 — SvelteKit 3 requires Vite 8, bringing faster builds powered by Rolldown.
- Config lives in
vite.config.ts— SvelteKit configuration moves out ofsvelte.config.jsand into your Vite config, so Vite plugins can read it right away. - Explicit environment variables are stable — Declare the environment variables your app depends on in
src/env.ts, and specify whether each one is public and whether it’s resolved at build time or when the app boots. You get validation and type safety out of the box. $libis now#lib— The$libalias is replaced by#lib, using Node’s subpath imports. Imports need to be unambiguous, so write#lib/foo.tsor#lib/foo/index.ts.- Shallow routing is built into
goto— Usegoto()withshallow: trueinstead ofpushStateandreplaceState. - Consistent error handling — All errors, including ones you throw with
error(...), now go through yourhandleErrorhook. - New service worker modules —
$service-workeris replaced by imports from$app/env,$app/paths, and$app/manifest, with better type checking in service workers. - Tracing is stable — Tracing support has moved out of the experimental namespace.
Check the full migration guide for all the details.
Watch out for the
#libaliasNearly every SvelteKit project imports from
$lib, so this is the change you’re most likely to run into. The migration tool rewrites these imports for you, but because#librelies on Node’s subpath imports, directory imports without an explicit file no longer resolve:// Beforeimport { formatDate } from '$lib/utils';// Afterimport { formatDate } from '#lib/utils/index.ts';If a build fails after upgrading with a module resolution error, look for
#libimports that point to a directory or leave off the file extension.Deploy a SvelteKit 3 site on Netlify
If you want to get started with a new site, start with the SvelteKit on Netlify doc, or just click this button: