Skip to content

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

Closed

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

Activity

  1. added theissue type on Feb 5, 2026
  2. ArnaudBarre commented on Feb 6, 2026

    @ArnaudBarre
    Member

    We can probably add babelOptions.overrides.length check.
    Out of curiosity, why do you have overrides without any plugins? (I never used the babel overrides option so I don't know its intent)

  3. gajus commented on Feb 6, 2026

    @gajus
    Author

    I want to apply Babel transformations only to parts of the project, that's what overrides without default plugins do.

  4. gajus commented on Feb 10, 2026

    @gajus
    Author

    Thank you

  5. locked and limited conversation to collaborators on Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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