Vite · Plugins

VITE0032Do not add serve-only hooks to build-only plugins

Reports configureServer, configurePreviewServer, handleHotUpdate, and hotUpdate hooks on Vite plugin objects with apply: "build".

Why it happens

Vite filters plugins by apply before calling these hooks. Dev, preview, and createServer use the serve command, so they exclude plugins whose apply is "build". Doctor checks objects it can trace to Vite config plugins or a factory with a Vite Plugin return type, and skips spreads, unresolved computed keys, and objects with unproven apply values. It does not report build output hooks on apply: "serve" plugins, because those can run in dev.

Fix

Remove apply: "build" or change it to apply: "serve" if the hook should run, or delete the hook.

Example

Keep serve hooks on plugins that run in serve

Before

import type { Plugin } from 'vite'

export function headers(): Plugin {
  return {
    name: 'headers',
    apply: 'build',
    configureServer(server) {
      server.middlewares.use(setHeaders)
    },
  }
}

After

import type { Plugin } from 'vite'

export function headers(): Plugin {
  return {
    name: 'headers',
    apply: 'serve',
    configureServer(server) {
      server.middlewares.use(setHeaders)
    },
  }
}

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --framework vite --rules vite/plugin/no-unreachable-hook
Copyright © 2026