Skip to content

$derived and $derived.by in {@const} tags results in obscure error message #15042

@theonlypwner

Description

@theonlypwner

Describe the bug

There is an error when using the $derived rune within a snippet.

Reproduction

https://svelte.dev/playground/hello-world?version=5.18.0#H4sIAAAAAAAACm2OTQ6CMBBGr1JHEyAhErYECe68g7gAOoYmdWjaETVN726qsnP7vp88D9TfECo4odazeMxWS5GiVIwygxyuSqOD6uyBXyb2IoB8XR2N2bsFNUc29A7_8XEmRmIHFfitI2UMsnBpn4WOOvbtOJNjMYiD2Em0akG5ZvVUNl8xP4RNXUxl05Evfh-xQr61SBKtcGnysU-yADkwPhkqtncMl_AGCs9xquUAAAA=

{#snippet s(a)}
	{@const b = $derived(a)}
	<h1>Hello {b}!</h1>
{/snippet}

{@render s('world')}

https://svelte.dev/playground/hello-world?version=5.18.0#H4sIAAAAAAAACm2PwQrCMBBEf2VdBVMoLV6LlnrzH6yHtlmxELchWasl5N-lWm9eH2-GmYDc3AkLPJExAzwHZzQo0r2QTjDFa2_IY3EOKJOdvRlg-ksdrc38SEZm1jae_vFuYCEWjwWGtefeWhLwqklizbWEqhvYC7RwgI0m14-ks3ZSKoFDCYu0v-3K78LQxtU-v-3KmkO-lM0Kh8oRa3Lg1fZzY5tETFHoJViIe1C8xDciFl9H7gAAAA==

{#snippet s(a)}
	{@const b = $derived.by(() => a)}
	<h1>Hello {b}!</h1>
{/snippet}

{@render s('world')}

Logs

rune_outside_svelte The `$derived` rune is only available inside `.svelte` and `.svelte.js/ts` files https://svelte.dev/e/rune_outside_svelte

System Info

Tested in Svelte REPL at `2025-01-17T02:55Z`

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions