Skip to content

[BABEL] babel() returns a Promise<Plugin> which lacks Vite-specific properties (enforce, apply) in its types #9

@sarkarghya

Description

@sarkarghya

Description

The current implementation of @rolldown/plugin-babel is asynchronous and returns a Promise<Plugin>. When using it in a Vite 8 project (especially for the React Compiler setup via reactCompilerPreset), it is often necessary to set Vite-specific properties like enforce: 'post'.

However, the returned Plugin type (likely following the core Rolldown/Rollup Hook interface) does not include these Vite-specific properties in its TypeScript definitions. Furthermore, because the function returns a Promise, developers must resolve it manually in the plugins array, which leads to poor ergonomics when a type cast is required to avoid TS errors.

Reproduction

In vite.config.ts:

import react, { reactCompilerPreset } from '@vitejs/plugin-react'
import babel from '@rolldown/plugin-babel';

export default defineConfig({
  plugins: [
    react(),
    // This results in a type error: Property 'enforce' does not exist on type 'Plugin<any>'
    babel({
      presets: [reactCompilerPreset()]
    }).then(p => {
      p.enforce = 'post';
      return p;
    }),
  ]
})

Current workaround:

babel({
  presets: [reactCompilerPreset()]
}).then((p: any) => {
  p.enforce = 'post';
  return p;
}),

Expected Behavior

Ideally, the plugin should be compatible with Vite's enforce and apply properties in its type definitions, or the React integration should offer a way to avoid this boilerplate. Since Vite 8 uses Rolldown as the engine, better alignment between Rolldown plugin types and Vite's expectations would improve the DX significantly.

Environment

  • @rolldown/plugin-babel: 0.2.0
  • vite: 8.0.0-beta.16
  • typescript: 6.0.1-rc

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions