-
-
Notifications
You must be signed in to change notification settings - Fork 231
Description
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
N/AUsed Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels