Skip to content

Destructuring $state array causes build to error #16093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
WaltzingPenguin opened this issue Jun 6, 2025 · 7 comments · Fixed by #16102
Closed

Destructuring $state array causes build to error #16093

WaltzingPenguin opened this issue Jun 6, 2025 · 7 comments · Fixed by #16102

Comments

@WaltzingPenguin
Copy link

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

> [email protected] 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

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Jun 6, 2025

It seems to work as expected here.

@MotionlessTrain
Copy link
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
Copy link
Member

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

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Jun 6, 2025

package.json says 5.33.14

@paoloricciuti
Copy link
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
Copy link
Contributor

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

@Ocean-OS
Copy link
Contributor

Ocean-OS commented Jun 6, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants