Skip to content

canSkipBabel does not account for overrides, causing Babel to be skipped entirely #1097

@gajus

Description

@gajus

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:

  1. In configResolved (production builds or rolldown-vite), the entire transform handler is deleted via delete viteBabel.transform — Babel never runs.
  2. 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/A

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions