Skip to content

Improve error message for trying to export a snippet that references variables inside a non module script #16474

@felix-tjernberg

Description

@felix-tjernberg

Describe the problem

When I saw the following error messages I did not quickly understand what caused the error

TS error (shown when hovering error in editor):
Cannot export 'snippet_name'. Only local declarations can be exported from a module.

vite-plugin-svelte error (shown in dev console or vite-error-overlay):
`snippet_name` is not defined
https://svelte.dev/e/export_undefined

Problematic code

<script module>
    export { snippet_name }
</script>

<script>
    let state = $state(true)
</script>

{#snippet snippet_name()}
    {#if state} ... {/if}
{/snippet}

Describe the proposed solution

It would be nice if the error message has similar phrasing to https://svelte.dev/docs/svelte/snippet#Exporting-snippets (or better yet links to that part of the documentation)

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions