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

6.0.0-beta.3 regression, all chunks grew significantly in size #18523

Closed
7 tasks done
sai-cb opened this issue Oct 30, 2024 · 6 comments · Fixed by #18573
Closed
7 tasks done

6.0.0-beta.3 regression, all chunks grew significantly in size #18523

sai-cb opened this issue Oct 30, 2024 · 6 comments · Fixed by #18573
Milestone

Comments

@sai-cb
Copy link

sai-cb commented Oct 30, 2024

Describe the bug

Starting with Vite 6.0.0-beta.3, all chunks produced in the dist directory significantly grew in size.

vite v6.0.0-beta.2 building for production...
✓ 216 modules transformed.
dist/index.html                 0.38 kB │ gzip: 0.26 kB
dist/assets/index-BueeJHUf.js  19.84 kB │ gzip: 8.84 kB
✓ built in 779ms

vite v6.0.0-beta.3 building for production...
✓ 125 modules transformed.
dist/index.html                 0.38 kB │ gzip:  0.26 kB
dist/assets/index-XnBmJTxy.js  25.16 kB │ gzip: 10.13 kB
✓ built in 774ms

I've internally been able to confirm the increase is seen across a large number of modules and seems loosely proportional to the size of the source code (e.g. a 1370kb chunk is becoming a 1420kb chunk). The issue appears to be systematic, as if minification somehow became less efficient across the board.

Reproduction

https://stackblitz.com/edit/vitejs-vite-jeh9rn?file=main.js

Steps to reproduce

  • Update Vite to either 6.0.0-beta.2 or 6.0.0-beta.3 in package.json
  • Run npm install
  • Run npm run build
  • Witness the size of the chunks

System Info

System:
    OS: macOS 15.1
    CPU: (10) arm64 Apple M2 Pro
    Memory: 159.98 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.17.0 - ~/.nvm/versions/node/v20.17.0/bin/node
    Yarn: 4.1.0 - ~/.nvm/versions/node/v20.17.0/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v20.17.0/bin/npm
    Watchman: 2024.08.26.00 - /opt/homebrew/bin/watchman
  Browsers:
    Chrome: 130.0.6723.91
    Firefox: 128.0
    Safari: 18.1
  npmPackages:
    vite: 6.0.0-beta.7 => 6.0.0-beta.3

Used Package Manager

npm

Logs

No response

Validations

@sai-cb
Copy link
Author

sai-cb commented Oct 30, 2024

This seems to have been introduced in the @rollup/plugin-commonjs update above v27. This version of the plugin changes the default strictRequires parameter from "auto" to true:

rollup/plugins#1639

The following workaround allows to avoid the bundlesize increase:

export default defineConfig(() => {
  return {
    build: {
      commonjsOptions: {
        strictRequires: 'auto',
      },
    },
  };
});

However unclear what the ideal path forward would be here and why strictRequires is introducing that regression...

@bluwy
Copy link
Member

bluwy commented Oct 30, 2024

I don't know if we're able to fix this other than plugin-commonjs trying to optimize the output a little. But from its docs, the larger output is expected as it's the safest option for deterministic builds that many have reported in #13672.

I think we should prefer the deterministic behaviour here to prevent unwanted issues down the road. If that's not an issue for you, you can set strictRequires: 'auto' manually. Or perhaps prefer ESM libraries more 😅

@sai-cb
Copy link
Author

sai-cb commented Oct 30, 2024

It may be worth to call out in the Release docs as this is a pretty tangible perf regression for production builds. A good number of consumers of Vite may be taken off guard by it.

@bluwy
Copy link
Member

bluwy commented Oct 30, 2024

Yeah we can add some more notes on this at https://main.vite.dev/guide/migration.html#advanced

@sai-cb
Copy link
Author

sai-cb commented Oct 30, 2024

(To be clear feel free to keep open or close as you think is appropriate)

I am not familiar enough to give good quality advise. On the surface, both issues seem problematic, and it is unclear if any improvements can be made to strictRequires: true. But at least there is the option to pick your poison 😆 .

@patak-dev patak-dev added this to the 6.0 milestone Oct 30, 2024
@bluwy
Copy link
Member

bluwy commented Oct 31, 2024

I think we can leave this open to track the documentation changes needed, no worries 👍 Thanks for testing out the beta!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants