Skip to content

regression: Plugin type no longer compatible with rollup #20948

@jendrikw

Description

@jendrikw

Describe the bug

I use @rollup/plugin-virtual like this:

plugins: [
        {
            enforce: "pre",
            ...virtual({
                "foo": "",
            })
        },
 // ...
]

I recently ran npm update, so I think this bug was introduced in one of the recent updates. I now get a typescript error:

vite.config.mjs:6:5 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Type '{ api?: any; cacheKey?: string | undefined; name: string; version?: string | undefined; augmentChunkHash?: ObjectHook<(this: PluginContext, chunk: RenderedChunk) => string | void, {}>; ... 26 more ...; enforce: "pre"; }' is not assignable to type 'PluginOption'.
      Type '{ api?: any; cacheKey?: string | undefined; name: string; version?: string | undefined; augmentChunkHash?: ObjectHook<(this: PluginContext, chunk: RenderedChunk) => string | void, {}>; ... 26 more ...; enforce: "pre"; }' is not assignable to type 'undefined'.

  6     {
        ~
  7       enforce: 'pre',
    ~~~~~~~~~~~~~~~~~~~~~
... 
 10       }),
    ~~~~~~~~~
 11     },
    ~~~~~

  node_modules/vite/dist/node/index.d.ts:3057:18
    3057 declare function defineConfig(config: UserConfigExport): UserConfigExport;
                          ~~~~~~~~~~~~
    The last overload is declared here.


Found 1 error in vite.config.mjs:6

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-fdvsxbh7?file=vite.config.mjs

Steps to reproduce

Run npm run check. Also reproducible on the typescript playground with a more detailed error message: https://www.typescriptlang.org/play/?useUnknownInCatchVariables=false&exactOptionalPropertyTypes=true#code/JYWwDg9gTgLgBDAnmApnA3gBQDYFcDmwAdgL5wBmUEIcARFdnmLQNwBQoksGAJiucRQBhCEQH4ylanQBuwGClZs2fAMbYAhlDSrRAZ3hgAXHBwFi7Ff0EixwfAAp0bAJBg8hInpMBtMAF0AGjYSAEplIA

No overload matches this call.
  The last overload gave the following error.
    Type 'Plugin<any>' is not assignable to type 'PluginOption'.
      Type 'Plugin<any>' is not assignable to type 'Plugin$1<any>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
        Types of property 'resolveId' are incompatible.
          Type 'ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: { attributes: Record<string, string>; custom?: CustomPluginOptions; isEntry: boolean; }) => ResolveIdResult | Promise<...>, { ...; }>' is not assignable to type 'ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: { attributes: Record<string, string>; custom?: CustomPluginOptions; ssr?: boolean; isEntry: boolean; }) => ResolveIdResult | Promise<...>, { ...; }>'.
            Type '{ handler: (this: PluginContext, source: string, importer: string | undefined, options: { attributes: Record<string, string>; custom?: CustomPluginOptions; isEntry: boolean; }) => ResolveIdResult | Promise<...>; order?: "pre" | ... 1 more ... | null; } & { ...; }' is not assignable to type 'ObjectHook<(this: PluginContext, source: string, importer: string | undefined, options: { attributes: Record<string, string>; custom?: CustomPluginOptions; ssr?: boolean; isEntry: boolean; }) => ResolveIdResult | Promise<...>, { ...; }>'.
              Type '{ handler: (this: PluginContext, source: string, importer: string | undefined, options: { attributes: Record<string, string>; custom?: CustomPluginOptions; isEntry: boolean; }) => ResolveIdResult | Promise<...>; order?: "pre" | ... 1 more ... | null; } & { ...; }' is not assignable to type '{ handler: (this: PluginContext, source: string, importer: string | undefined, options: { attributes: Record<string, string>; custom?: CustomPluginOptions; ssr?: boolean; isEntry: boolean; }) => ResolveIdResult | Promise<...>; order?: "pre" | ... 1 more ... | null; } & { ...; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                Type '{ handler: (this: PluginContext, source: string, importer: string | undefined, options: { attributes: Record<string, string>; custom?: CustomPluginOptions; isEntry: boolean; }) => ResolveIdResult | Promise<...>; order?: "pre" | ... 1 more ... | null; } & { ...; }' is not assignable to type '{ filter?: { id?: StringFilter<RegExp>; }; }' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                  The types of 'filter.id' are incompatible between these types.
                    Type 'StringFilter<RegExp> | undefined' is not assignable to type 'StringFilter<RegExp>'.
                      Type 'undefined' is not assignable to type 'StringFilter<RegExp>'.

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 20.19.1 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: latest => 7.1.10

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions