vite icon indicating copy to clipboard operation
vite copied to clipboard

Vite Build Issue: Source Code Lost After Build

Open wqcstrong opened this issue 2 months ago • 3 comments

Describe the bug

When creating a project with yarn create vite using the default Vite bundler, source code is lost in the build output. However, when using rolldown-vite as an alternative bundler, everything works correctly.

Default Vite Rolldown Vite
yarn dev
yarn build && yarn preview

I've included more details in the reproduction link.

Reproduction

https://github.com/wqcstrong/vite-lost-code-after-build?tab=readme-ov-file

Steps to reproduce

No response

System Info

System:
    OS: macOS 26.0
    CPU: (10) arm64 Apple M4
    Memory: 289.56 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.18.0 - /Users/blucas/.nvm/versions/node/v22.18.0/bin/node
    Yarn: 1.22.22 - /usr/local/bin/yarn
    npm: 10.9.3 - /Users/blucas/.nvm/versions/node/v22.18.0/bin/npm
  Browsers:
    Chrome: 142.0.7444.162
    Edge: 142.0.3595.53
    Safari: 26.0

Used Package Manager

yarn

Logs

No response

Validations

wqcstrong avatar Nov 14 '25 05:11 wqcstrong

This sounds like a bug in rollup. Would you try if you can create a reproduction with raw Rollup?

sapphi-red avatar Nov 14 '25 10:11 sapphi-red

Minimal reproduction of the issue:

class A {
  constructor() {
    const local = (this.b = {})
    Object.defineProperty(local, 'c', { value: 42 })
  }
}
console.log(new A().b.c) //=> 42

Rollup output:

class A {
  constructor() {
    (this.b = {});
  }
}
console.log(new A().b.c); //=> undefined

Rollup tree-shakes away the local variable and side-effects applied to it.

Rollup REPL


@wqcstrong As quick "fix" on your side you could help out Rollup a bit and extract the chained assignments to separate statements in createUniforms and createBuffers. E.g.:

const values = (this.uniforms = {} as Record<string, unknown>);
// =>
this.uniforms = {};
const values = this.uniforms;

jtlehtinen avatar Nov 15 '25 12:11 jtlehtinen

@jtlehtinen Thank you for trimming it down. Would you create an issue to Rollup as well?

sapphi-red avatar Nov 15 '25 13:11 sapphi-red