Extending Doctor

Ship with a library

Ship Doctor Rules with a Vite plugin or a Nuxt module so users get them without setup.

A library can ship its Doctor Extension so users who install it get its Rules without extra setup. Put the extension in its own entry, such as ./doctor, and point the Vite plugin, the Nuxt module, or both at it.

Ship Rules with a Vite plugin

A Vite plugin exposes Doctor Extensions as api.doctor. The doctor() plugin reads api.doctor.extensions from every plugin in the resolved Vite config:

src/vite.ts
import type { Plugin } from "vite";
import type { DoctorPluginApi } from "vite-doctor/extension";

export function acme(): Plugin {
  return {
    name: "acme",
    api: {
      doctor: {
        extensions: [() => import("./doctor.js")],
      } satisfies DoctorPluginApi,
    },
  };
}
vite.config.ts
import { acme } from "acme/vite";
import { doctor } from "vite-doctor";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [acme(), doctor()],
});

An entry is a Doctor Extension, or a loader that returns one or a module with a default export. Use a loader so your plugin imports Doctor code only during a Doctor Run. Then vite-doctor can stay an optional peer dependency:

package.json
{
  "exports": {
    "./doctor": "./dist/doctor.mjs"
  },
  "peerDependencies": { "vite-doctor": "*" },
  "peerDependenciesMeta": { "vite-doctor": { "optional": true } }
}

The type import is erased at build time. If your package already depends on vite-doctor at runtime, defineDoctorPluginApi({ extensions }) from vite-doctor/extension gives the same typing.

Ship Rules with a Nuxt module

A Nuxt module registers extension entry modules through the doctor:extendExtensions hook. Push a path, file: URL, or package specifier whose default export is a Doctor Extension:

src/module.ts
import { createResolver, defineNuxtModule } from "@nuxt/kit";
import type {} from "vite-doctor/nuxt";

export default defineNuxtModule({
  meta: { name: "acme" },
  setup(_options, nuxt) {
    const { resolve } = createResolver(import.meta.url);
    nuxt.hook("doctor:extendExtensions", (entries) => {
      entries.push(resolve("./doctor"));
    });
  },
});

import type {} from "vite-doctor/nuxt" loads the hook types and is erased at build time. Without vite-doctor/nuxt installed, the hook never runs.

Users add both modules and run the Nuxt Doctor Command:

nuxt.config.ts
export default defineNuxtConfig({
  modules: ["acme", "vite-doctor/nuxt"],
});
pnpm nuxt prepare
pnpm nuxt doctor

The Nuxt 4 Bridge resolves each entry to an absolute file and records it in .nuxt/doctor.manifest.json during nuxt dev, nuxt build, and nuxt prepare. nuxt doctor loads the recorded entries because it is a Nuxt host command; running it is the same trust decision as nuxt dev. The standalone CLI runs host-registered code only with --host-extensions. On Nuxt 4.1 to 4.5, where nuxt doctor exits 0 whatever Doctor finds, use that flag in CI:

pnpm vite-doctor . --host-extensions --max-warnings 0

Doctor loads entries with Node's native import(), so publish built JavaScript. A TypeScript entry works when Node can strip its types and its relative imports include file extensions. For a local module in your app, keep the entry outside modules/, because Nuxt registers every file there as a module.

If an entry fails to load or its default export is not a Doctor Extension, the run stops with DOC0029. Rebuild the package and run nuxt prepare again.

A package that ships both a Vite plugin and a Nuxt module can point both at the same ./doctor entry.

Copyright © 2026