Related plugins
Describe the bug
When configuring babel.overrides without any top-level plugins or presets, the canSkipBabel function incorrectly determines that Babel can be skipped. This causes override test functions/patterns to never be evaluated, and override plugins to never run.
The test callback is never invoked. No override plugins are applied.
https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L563-L573
function canSkipBabel(
plugins: ReactBabelOptions['plugins'],
babelOptions: ReactBabelOptions,
) {
return !(
plugins.length ||
babelOptions.presets.length ||
babelOptions.configFile ||
babelOptions.babelrc
)
}
It does not check babelOptions.overrides.length. When overrides are the sole source of plugins, this function returns true and Babel is skipped.
This has two effects:
- In configResolved (production builds or rolldown-vite), the entire transform handler is deleted via delete viteBabel.transform — Babel never runs.
- In the per-file transform path, the early return at if (canSkipBabel(...)) return prevents Babel from processing the file.
Reproduction
https://
Steps to reproduce
react({
babel: {
overrides: [
{
plugins: ['babel-plugin-react-compiler'],
test: /\+Page\.tsx?$/,
},
{
plugins: ['babel-plugin-zod-hoist'],
test: (filename) => {
console.log('filename>>>', filename); // never fires
return filename?.endsWith('.tsx') ?? false;
},
},
],
},
}),
System Info
Used Package Manager
npm
Logs
No response
Validations
Related plugins
plugin-react
plugin-react-swc
plugin-react-oxc
plugin-rsc
Describe the bug
When configuring
babel.overrideswithout any top-level plugins or presets, thecanSkipBabelfunction incorrectly determines that Babel can be skipped. This causes override test functions/patterns to never be evaluated, and override plugins to never run.The test callback is never invoked. No override plugins are applied.
https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/index.ts#L563-L573
It does not check
babelOptions.overrides.length. When overrides are the sole source of plugins, this function returns true and Babel is skipped.This has two effects:
Reproduction
https://
Steps to reproduce
System Info
Used Package Manager
npm
Logs
No response
Validations