Describe the bug
I am trying to pre-bundle dependencies for a legacy browser target (Chrome 81) by setting optimizeDeps.rolldownOptions.transform.target. What I expect is that Rolldown transpiles dep output to the configured target so that modern syntax like ??=, ?., class fields, etc. gets lowered. What actually happens is that the pre-bundled files in node_modules/.vite/deps/ still contain untranspiled modern syntax — the user-supplied target is ignored.
Root cause
In packages/vite/src/node/optimizer/index.ts (v8, prepareRolldownOptimizerRun), the options passed to rolldown() are built as:
transform: {
...rolldownOptions.transform, // user config spread first
target: ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET, // hardcoded — overwrites user's target
define
},
In v7, the hardcoded default is placed before ...esbuildOptions:
target: ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
...
...esbuildOptions, // user config spread last, can override
supported: {
...defaultEsbuildSupported,
...esbuildOptions.supported,
},
So in v7 optimizeDeps.esbuildOptions.target correctly overrode the default. The v8 rewrite around rolldown flipped the spread order and silently broke this contract.
Suggested fix
transform: {
target: ESBUILD_BASELINE_WIDELY_AVAILABLE_TARGET,
...rolldownOptions.transform,
define
},
Reproduction
https://stackblitz.com/edit/vitejs-vite-du3yfmdq?file=vite.config.js
Steps to reproduce
- Vite 8 project with any dep shipping ES2021+ syntax (e.g. vue-router@5 uses ??=).
- vite.config.js:
import { defineConfig } from 'vite'
export default defineConfig({
optimizeDeps: {
rolldownOptions: {
transform: { target: 'chrome81' },
},
},
})
- Run vite --force to rebuild the dep cache.
- Open node_modules/.vite/deps/vue-router.js. Expected: ??= etc. lowered for chrome81. Actual: untransformed.
System Info
Used Package Manager
pnpm
Logs
No response
Validations
Describe the bug
I am trying to pre-bundle dependencies for a legacy browser target (Chrome 81) by setting optimizeDeps.rolldownOptions.transform.target. What I expect is that Rolldown transpiles dep output to the configured target so that modern syntax like ??=, ?., class fields, etc. gets lowered. What actually happens is that the pre-bundled files in node_modules/.vite/deps/ still contain untranspiled modern syntax — the user-supplied target is ignored.
Root cause
In
packages/vite/src/node/optimizer/index.ts(v8, prepareRolldownOptimizerRun), the options passed to rolldown() are built as:In v7, the hardcoded default is placed before ...esbuildOptions:
So in v7 optimizeDeps.esbuildOptions.target correctly overrode the default. The v8 rewrite around rolldown flipped the spread order and silently broke this contract.
Suggested fix
Reproduction
https://stackblitz.com/edit/vitejs-vite-du3yfmdq?file=vite.config.js
Steps to reproduce
System Info
Used Package Manager
pnpm
Logs
No response
Validations