Skip to content
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

class rune edgecase (rollup different from esbuild) #15629

Open
JakeBeaver opened this issue Mar 28, 2025 · 0 comments
Open

class rune edgecase (rollup different from esbuild) #15629

JakeBeaver opened this issue Mar 28, 2025 · 0 comments

Comments

@JakeBeaver
Copy link
Contributor

Describe the bug

Found a behavior difference beween pnpm dev and pnpm preview, when referencing a state property as a default constructor arg.

I do realise what I did is unorthodox and unnecessary, but it's interesting that esbuild breaks it nonetheless

<script>
    class A {
        a = $state("test");
        constructor(init = /* this causes it to fail: */ this.a){
            this.a = init;
        }
    }

    const a = new A();
</script>

{a.a}

Image

Reproduction

  • scaffold a basic sveltekit app
npx sv create
  • put this in ./src/routes/+page.svelte
<script>
    class A {
        a = $state("test");
        constructor(init = /* this causes it to fail: */ this.a){
            this.a = init;
        }
    }

    const a = new A();
</script>

{a.a}
  • run dev server and observe it works fine
pnpm dev
  • run a build and preview, observe browser console error
pnpm build
pnpm preview

Logs

2.DfF_Z-xm.js:1 Uncaught (in promise) TypeError: Cannot read from private field
    at n (2.DfF_Z-xm.js:1:17)
    at c (2.DfF_Z-xm.js:1:56)
    at r (2.DfF_Z-xm.js:1:87)
    at get a (2.DfF_Z-xm.js:1:534)
    at new a (2.DfF_Z-xm.js:1:485)
    at q (2.DfF_Z-xm.js:1:595)
    at app.BtHtryw3.js:2:6003
    at app.BtHtryw3.js:2:1529
    at an (DEKecDdA.js:1:11051)
    at bt (DEKecDdA.js:1:11936)

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 38.06 GB / 63.68 GB
  Binaries:
    Node: 22.11.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.9.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.12.3 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.2.5 - C:\Program Files\nodejs\bun.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527

Severity

annoyance

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

No branches or pull requests

1 participant