sveltejs/svelte · error · Error
lifecycle_legacy_only
lifecycle_legacy_only
Error message
lifecycle_legacy_only
`${name}(...)` cannot be used in runes mode
https://svelte.dev/e/lifecycle_legacy_only What it means
Thrown at index-client.js:206 and :229 inside beforeUpdate()/afterUpdate() when component_context.l is null, i.e. the component is in runes mode. These legacy lifecycle hooks rely on the pre-runes reactivity model and have no equivalent semantics under runes; Svelte 5 runes components must use $effect / $effect.pre instead.
Source
Thrown at packages/svelte/src/internal/client/errors.js:377
} else {
throw new Error(`https://svelte.dev/e/invalid_snippet`);
}
}
/**
* `%name%(...)` cannot be used in runes mode
* @param {string} name
* @returns {never}
*/
export function lifecycle_legacy_only(name) {
if (DEV) {
const error = new Error(`lifecycle_legacy_only\n\`${name}(...)\` cannot be used in runes mode\nhttps://svelte.dev/e/lifecycle_legacy_only`);
error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/lifecycle_legacy_only`);
}
}
/**
* Cannot do `bind:%key%={undefined}` when `%key%` has a fallback value
* @param {string} key
* @returns {never}
*/
export function props_invalid_value(key) {
if (DEV) {
const error = new Error(`props_invalid_value\nCannot do \`bind:${key}={undefined}\` when \`${key}\` has a fallback value\nhttps://svelte.dev/e/props_invalid_value`);
error.name = 'Svelte error';
throw error;
} else {
throw new Error(`https://svelte.dev/e/props_invalid_value`);
}View on GitHub (pinned to 20b341f100)
Solutions
- Replace beforeUpdate(fn) with $effect.pre(fn).
- Replace afterUpdate(fn) with $effect(fn).
- Remove the legacy import (beforeUpdate/afterUpdate) once migrated.
Example fix
// before
import { beforeUpdate, afterUpdate } from 'svelte';
beforeUpdate(() => { /* ... */ });
afterUpdate(() => { /* ... */ });
// after
$effect.pre(() => { /* runs before DOM update */ });
$effect(() => { /* runs after DOM update */ }); Defensive patterns
Strategy: validation
Validate before calling
// Do not call beforeUpdate/afterUpdate in runes-mode components. // Detect runes mode: if your component uses $state/$props/$effect, it is in runes mode. // Replace beforeUpdate -> $effect.pre, afterUpdate -> $effect.
Prevention
- During Svelte 4 -> 5 migration, replace beforeUpdate/afterUpdate with $effect.pre/$effect.
- Remove legacy lifecycle imports once a component uses runes.
- Audit library dependencies that call these hooks before using them from runes components.
When it happens
Trigger: Importing and calling beforeUpdate(fn) or afterUpdate(fn) in a component that opts into runes mode (either explicitly via runes: true or implicitly because it uses runes like $state/$props). The guard checks component_context.l === null.
Common situations: Migrating a Svelte 4 component to Svelte 5 runes while leaving beforeUpdate/afterUpdate calls in place; copying legacy code into a runes component; library code that calls these hooks being used from a runes-mode app.
Related errors
- effect_orphan
- set_context_after_init
- migrating this component would require adding a `$${rune}` r
- can't migrate `${...}` to `$${rune}` because there's a varia
- effect_in_teardown
AI-assisted analysis of sveltejs/svelte@20b341f100 (2026-08-12).
Data as JSON: /api/errors/f338b5df99b84929.
Report an issue: GitHub.