Перейти к содержимому

Ошибки рантайма

Using `bind:value` together with a checkbox input is not allowed. Use `bind:checked` instead
Component %component% has an export named `%key%` that a consumer component is trying to access using `bind:%key%`, which is disallowed. Instead, use `bind:this` (e.g. `<%name% bind:this={component} />`) and then access the property on the bound component instance (e.g. `component.%key%`)
A component is attempting to bind to a non-bindable property `%key%` belonging to %component% (i.e. `<%name% bind:%key%={...}>`). To mark a property as bindable: `let { %key% = $bindable() } = $props()`
Calling `%method%` on a component instance (of %component%) is no longer valid in Svelte 5

Дополнительную информацию можно найти в руководстве по миграции.

Attempted to instantiate %component% with `new %name%`, which is no longer valid in Svelte 5. If this component is not under your control, set the `compatibility.componentApi` compiler option to `4` to keep it working.

Дополнительную информацию можно найти в руководстве по миграции.

A derived value cannot reference itself recursively
Keyed each block has duplicate key at indexes %a% and %b%
Keyed each block has duplicate key `%value%` at indexes %a% and %b%
`%rune%` cannot be used inside an effect cleanup function
Effect cannot be created inside a `$derived` value that was not itself created inside an effect
`%rune%` can only be used inside an effect (e.g. during component initialisation)
Maximum update depth exceeded. This can happen when a reactive block or effect repeatedly sets a new value. Svelte limits the number of nested updates to prevent infinite loops
Failed to hydrate the application
Could not `{@render}` snippet due to the expression being `null` or `undefined`. Consider using optional chaining `{@render snippet?.()}`
`%name%(...)` cannot be used in runes mode
Cannot do `bind:%key%={undefined}` when `%key%` has a fallback value
Rest element properties of `$props()` such as `%property%` are readonly
The `%rune%` rune is only available inside `.svelte` and `.svelte.js/ts` files
Property descriptors defined on `$state` objects must contain `value` and always be `enumerable`, `configurable` and `writable`.
Cannot set prototype of `$state` object
Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`

Эта ошибка возникает при обновлении состояния во время вычисления $derived. Вы можете столкнуться с ней при попытке «вывести» (derive) два состояния за один раз:

<script>
let count = $state(0);
let even = $state(true);
let odd = $derived.by(() => {
even = count % 2 === 0;
return !even;
});
</script>
<button onclick={() => count++}>{count}</button>
<p>{count} чётное: {even}</p>
<p>{count} нечётное: {odd}</p>

Это запрещено, так как приводит к нестабильности: если <p>{count} чётное: {even}</p> обновится до пересчёта odd, значение even окажется устаревшим. В большинстве случаев решением является использование производных значений для всех зависимостей:

let even = $derived(count % 2 === 0);
let odd = $derived(!even);

Если побочные эффекты неизбежны, используйте руну $effect.

`%name%(...)` is not available on the server

Некоторые методы, такие как mount, не могут быть вызваны в серверном контексте. Избегайте их преждевременного вызова, то есть не вызывайте их во время рендеринга.

Cannot use `{@render children(...)}` if the parent component uses `let:` directives. Consider using a named snippet instead

Эта ошибка возникает в подобных случаях:

Parent.svelte
<List {items} let:entry>
<span>{entry}</span>
</List>
List.svelte
<script>
let { items, children } = $props();
</script>
<ul>
{#each items as item}
<li>{@render children(item)}</li>
{/each}
</ul>

В данном случае List.svelte использует {@render children(item)}, что означает ожидание сниппетов от родительского компонента. Однако Parent.svelte использует устаревшую директиву let:. Эти API несовместимы, отсюда и ошибка.

A snippet function was passed invalid arguments. Snippets should only be instantiated via `{@render ...}`
`%name%(...)` can only be used during component initialisation

Некоторые методы жизненного цикла могут использоваться только во время инициализации компонента. Чтобы исправить это, убедитесь, что вы вызываете метод на верхнем уровне тега script компонента:

<script>
import { onMount } from 'svelte';
function handleClick() {
// Неправильно
onMount(() => {})
}
// Правильно
onMount(() => {})
</script>
<button onclick={handleClick}>нажми меня</button>
Attempted to render a snippet without a `{@render}` block. This would cause the snippet code to be stringified instead of its content being rendered to the DOM. To fix this, change `{snippet}` to `{@render snippet()}`.

Вот как может выглядеть компонент, вызывающий эту ошибку (при этом children не отображается):

<script>
let { children } = $props();
</script>
{children}

…или так (родительский компонент передаёт сниппет, хотя ожидается не сниппет):

Parent.svelte
<ChildComponent>
{#snippet label()}
<span>Привет!</span>
{/snippet}
</ChildComponent>
Child.svelte
<script>
let { label } = $props();
</script>
<!-- Этот компонент не ожидает сниппет, но родительский компонент предоставил его -->
<p>{label}</p>
`%name%` is not a store with a `subscribe` method
The `this` prop on `<svelte:element>` must be a string, if defined