Skip to content

Svelte 5: each block with index causes error (works with svelte 4) #9636

@amit13k

Description

@amit13k

Describe the bug

The following code examples (which work properly with svelte 4) produce errors with Svelte 5,

{#each ["a", "b"] as result, i (i)}
  <div>{result}</div>
{/each}
{#each ["a", "b"] as result, i (i)}
  <div>{i}</div>
{/each}
<!-- This (with only one element) doesn't produce any errors. -->
{#each ["a"] as result, i (i)}
  <div>{result}</div>
{/each}

Reproduction

Example 1 Svelte 5 REPL

Example 2 Svelte 5 REPL

Logs

No response

System Info

System:
    OS: macOS 14.2
    CPU: (12) arm64 Apple M2 Pro
    Memory: 213.45 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 21.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 6.14.16 - /opt/homebrew/bin/npm
    pnpm: 8.10.5 - /opt/homebrew/bin/pnpm
    bun: 1.0.3 - ~/.bun/bin/bun
  Browsers:
    Chrome: 119.0.6045.159
    Chrome Canary: 121.0.6145.0
    Safari: 17.2

Severity

annoyance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions