Skip to content

Destructuring $state array causes build to error #16093

@WaltzingPenguin

Description

@WaltzingPenguin

Describe the bug

Array destructuring from $state causes the build to error. This was working in 5.33.4 but is broken in the latest 5.33.14

Reproduction

Include the line let [level, custom] = $state([10, "Admin"]) in a Svelte file in your project and then attempt to build.

Or:

Repo: https://github.com/WaltzingPenguin/sveltekit-expected-ident
Install project and execute npm run build

Logs

PS C:\Users\Admin\Documents\Web Projects\sveltekit-unexpected-ident> npm run build

> sveltekit-unexpected-ident@0.0.1 build
> vite build

vite v6.3.5 building SSR bundle for production...
✓ 15 modules transformed.
✗ Build failed in 69ms
error during build:
src/routes/unexpected-ident.svelte (2:10): Expected ident (Note that you need plugins to import files that are not JavaScript)
file: C:/Users/Admin/Documents/Web Projects/sveltekit-unexpected-ident/src/routes/unexpected-ident.svelte:2:10

1: <script lang="ts">
2: let [level, custom] = $state([10, "Admin"])
             ^
3: </script>

    at getRollupError (file:///C:/Users/Admin/Documents/Web%20Projects/sveltekit-unexpected-ident/node_modules/rollup/dist/es/shared/parseAst.js:401:41)
    at ParseError.initialise (file:///C:/Users/Admin/Documents/Web%20Projects/sveltekit-unexpected-ident/node_modules/rollup/dist/es/shared/node-entry.js:14293:28)
    at convertNode (file:///C:/Users/Admin/Documents/Web%20Projects/sveltekit-unexpected-ident/node_modules/rollup/dist/es/shared/node-entry.js:16197:10)
    at convertProgram (file:///C:/Users/Admin/Documents/Web%20Projects/sveltekit-unexpected-ident/node_modules/rollup/dist/es/shared/node-entry.js:15440:12)
    at Module.setSource (file:///C:/Users/Admin/Documents/Web%20Projects/sveltekit-unexpected-ident/node_modules/rollup/dist/es/shared/node-entry.js:17185:24)
    at async ModuleLoader.addModuleSource (file:///C:/Users/Admin/Documents/Web%20Projects/sveltekit-unexpected-ident/node_modules/rollup/dist/es/shared/node-entry.js:21187:13)

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600KF
    Memory: 48.03 GB / 63.85 GB
  Binaries:
    Node: 22.13.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 10.2.0 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Chromium (134.0.3124.83)
    Internet Explorer: 11.0.26100.1882

Severity

blocking an upgrade

Activity

Ocean-OS

Ocean-OS commented on Jun 6, 2025

@Ocean-OS
Member

It seems to work as expected here.

MotionlessTrain

MotionlessTrain commented on Jun 6, 2025

@MotionlessTrain
Contributor

It looks like a rollup error. But I don’t see how the JavaScript output from the svelte component could trigger that error

paoloricciuti

paoloricciuti commented on Jun 6, 2025

@paoloricciuti
Member

Something similar was fixed recently, which version of svelte are you on?

Ocean-OS

Ocean-OS commented on Jun 6, 2025

@Ocean-OS
Member

package.json says 5.33.14

paoloricciuti

paoloricciuti commented on Jun 6, 2025

@paoloricciuti
Member

Oh well... here's the generated server code lol

import * as $ from 'svelte/internal/server';

export default function App($$payload) {
	let tmp = [10, "Admin"],
		level = #[0],
		custom = #[1];

	$$payload.out += `<!---->${$.escape(level)}, ${$.escape(custom)}`;
}
MotionlessTrain

MotionlessTrain commented on Jun 6, 2025

@MotionlessTrain
Contributor

Whoops, I only checked the client code when I was curious whether I could find it 😄

Ocean-OS

Ocean-OS commented on Jun 6, 2025

@Ocean-OS
Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @WaltzingPenguin@MotionlessTrain@paoloricciuti@Ocean-OS

      Issue actions

        Destructuring $state array causes build to error · Issue #16093 · sveltejs/svelte