Svelte provides a powerful migration script that handles much of the tedious work.
Running the Migration
bash# Navigate to your project cd my-svelte-app # Run the migration npx sv migrate svelte-5
What the Script Does
1. Updates Configuration Files:
svelte.config.jsvite.config.jstsconfig.json
2. Converts Event Syntax:
svelte<!-- Before --> <button on:click={handler}>Click</button> <!-- After --> <button onclick={handler}>Click</button>
3. Updates Imports:
javascript// Some internal imports may change
What It DOESN'T Do (You Must Do Manually)
- Convert
let x = 0tolet x = $state(0) - Convert
$: derived = ...to$derived(...) - Replace
createEventDispatcherwith callback props - Convert
<slot />to snippets - Migrate Svelte stores to Runes
Running on Specific Files
bash# Migrate a specific component npx sv migrate svelte-5 src/lib/MyComponent.svelte # Migrate a directory npx sv migrate svelte-5 src/routes/
After Running the Script
- Review changes - Check git diff for what changed
- Run your app - Make sure it still works
- Fix errors - Address any TypeScript or runtime errors
- Test thoroughly - Run your test suite