Skip to content

import scan merges script contexts causing duplicate variables and esbuild failure #5446

@benmccann

Description

@benmccann

Describe the bug

Vite merges scripts together from .svelte files that the Svelte compiler treats as separate scripts:

js += content + '\n'

Reproduction

npm init svelte@next my-app
cd my-app

Add to src/routes/index.svelte:

<script context="module">
let top;
</script>
<script>
export let top;
</script>

And then run npm run dev or npm run build

System Info

Vite 2.6.12

Used Package Manager

npm

Logs

html:src/routes/index.svelte:59:12: error: "top" has already been declared

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions