-
-
Notifications
You must be signed in to change notification settings - Fork 17
Expected polyfills not applied when using @vitejs/plugin-legacy when using [email protected] or later #404
Description
Describe the regression
When using @vitejs/plugin-legacy, the final build doesn't contain the polyfills it should. The behavior of rolldown-vite is different than that of vite.
Reproduction
https://stackblitz.com/edit/vitejs-vite-xjjempqm?file=vite.config.ts
Expected Behavior
I expect a polyfill for private class fields to be introduced to the final bundle when targeting certain browsers. given the following source code...
class BuilderReport {
#name = 'Vite';
getName() {
return this.#name;
}
}
const report = new BuilderReport()
console.log(report.getName())...and this config for @vitejs/plugin-legacy:
legacy({
modernPolyfills: true,
targets: ['ios_saf >= 13', 'safari >= 13'],
renderLegacyChunks: false,
})...the#name field should be polyfilled. This does happen in Vite, but not in rolldown-vite.
Actual Behavior
In rolldown-vite builds, the build process does not add a polyfill for #name.
Edit to add: This difference in behavior only occurs in versions in [email protected] and up. In my repro link, running rolldown @ 7.1.2 explicitly produces the results I expect:
# Pinning to 7.1.2 applies polyfills
npx -y [email protected] build --outDir ./dist-rolldown
# Using latest does not apply polyfills
npx -y rolldown-vite build --outDir ./dist-rolldownMaybe this has to do with enableNativePlugin being set to true by default?
Steps to Reproduce
- Run
npm install - Run
npm run build && npm run build:rolldown - In the
distdirectory, which is produced by Vite, note that the JS asset includes a__privateAdd()polyfill for the#namefield - In the
dist-rolldowndirectory, which is produced by rolldown-vite, note that the JS asset includes the#namefield with no polyfill
System Info
System:
OS: macOS 15.6.1
CPU: (10) arm64 Apple M4
Memory: 106.47 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.11.1 - ~/.local/state/fnm_multishells/25078_1757435370919/bin/node
npm: 10.2.4 - ~/.local/state/fnm_multishells/25078_1757435370919/bin/npm
bun: 1.2.20 - ~/.bun/bin/bun
Browsers:
Chrome: 140.0.7339.81
Safari: 18.6Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs and the Rolldown-related guide.
- Check that there isn't already an issue that reports the same regression to avoid creating a duplicate.
- Check that this is a concrete regression. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the regression.