Skip to content

DTK0023: Vite Server Required

Package: @vitejs/devtools

Message

viteServer is required in dev mode

Cause

The DevToolsViewHost.hostStatic() method was called while Vite is running in serve (dev) mode, but the viteServer instance on the DevTools context is not available. In dev mode, the view host needs the Vite dev server to register its middleware for serving static files via sirv. This can happen if hostStatic() is called before the Vite server has been fully initialized and attached to the context.

Example

ts
export default defineDevToolsPlugin({
  name: 'my-plugin',
  setup(context) {
    // If viteServer is not yet set on the context in dev mode,
    // this throws DTK0023
    context.views.hostStatic(
      '/.my-plugin/',
      resolve(__dirname, '../client/dist'),
    )
  },
})

Fix

Ensure hostStatic() is called after the Vite dev server is available on the context. In most cases, calling it within the setup hook of defineDevToolsPlugin should work because the server is initialized before plugins are set up. If you are calling it from an asynchronous callback, verify that context.viteServer is defined.

ts
export default defineDevToolsPlugin({
  name: 'my-plugin',
  setup(context) {
    if (context.viteConfig.command === 'serve' && !context.viteServer) {
      // Wait or handle the case where the server isn't ready
      return
    }
    context.views.hostStatic('/.my-plugin/', distDir)
  },
})

Source

packages/core/src/node/host-views.ts

Released under the MIT License.