The vite-doctor/h3 Rule Pack checks code written against H3, the HTTP framework under Nitro and Nuxt. It covers request validation, responses, request bodies, HTTP errors, sessions, middleware paths, and the APIs H3 v2 removed or changed. Its diagnostics use the H3 Diagnostic Code Prefix.
When it runs
The pack activates per workspace package. A package activates it when it declares h3 in its dependencies, such as an H3 server on srvx, or when it is a Nitro or Nuxt project, which runs H3 without declaring it. Nitro and Nuxt projects get every H3 rule without extra config.
Most rules target H3 v2, so they read the H3 version each package runs. A package that declares h3 resolves its own installed copy. A Nitro or Nuxt package uses the H3 that its Nitro owns. The JSON and agent reports list the result for each package under workspacePackages[].runtimes.h3, with its state, version, and owner. When a package declares h3 but Doctor cannot find it installed, the runtime is unknown, Doctor reports DOC0022, and the version-gated rules stay off for that package.
What Doctor reads
In Nitro and Nuxt server files, H3 utilities are auto-imported, so a free readBody or createError counts as H3's.
Everywhere else, Doctor checks a file only when it has a value import from h3 or nitro/h3. Inside that file, a call counts only when it resolves to that import, through a named, aliased, or namespace import. A local function named getHeader is not H3's, and a free createError in a standalone H3 server is not either. Test files are skipped.
Install and run
Install Vite Doctor in the project:
pnpm add -D vite-doctor
The Recommended Preset runs automatically:
pnpm vite-doctor .
The Strict Preset adds h3/middleware/no-exact-path-use, which reports middleware paths that may be exact on purpose:
pnpm vite-doctor . --extends auto,h3/strict
To diagnose one Rule, select it with --rules:
pnpm vite-doctor . --rules h3/request/prefer-validated-body
Rules
Rules marked v2 run only where the package runs H3 2.0 or later, prereleases included.
Request
| Code | Rule | Severity | H3 |
|---|---|---|---|
| H30005 | h3/request/prefer-assert-method | info | any |
| H30006 | h3/request/prefer-get-request-ip | warn | any |
| H30007 | h3/request/prefer-validated-body | info | any |
| H30008 | h3/request/prefer-validated-query | info | any |
| H30009 | h3/request/prefer-validated-router-params | warn | any |
Response
| Code | Rule | Severity | H3 |
|---|---|---|---|
| H30010 | h3/response/no-event-first-arg | error | v2 |
| H30011 | h3/response/no-discarded-response | error | v2 |
| H30012 | h3/response/no-prepared-status-with-response | warn | v2 |
| H30013 | h3/response/no-html-plain-string | warn | 2.0.1-rc.26 and later |
Body, errors, and security
| Code | Rule | Severity | H3 |
|---|---|---|---|
| H30016 | h3/body/no-double-body-read | error | v2 |
| H30004 | h3/errors/no-http-error-masking | warn | any |
| H30014 | h3/errors/no-numeric-create-error | error | any |
| H30015 | h3/errors/no-throw-plain-object | error | v2 |
| H30017 | h3/security/session-password-too-short | error | any |
| H30021 | h3/security/no-guard-after-validation | warn | v2 |
h3/security/no-guard-after-validation reads defineValidatedHandler and the defineEndpoint of h3-route-tools. Both validate the request before they call the handler: H3 validates query and headers, and h3-route-tools also validates params. When the handler starts with await requireUserSession(event) or another auth guard, validation can reject a guest's request (400 by default) before the guard runs. The rule reports such routes when they have no middleware:
export default defineValidatedHandler({
middleware: [
onRequest(async (event) => {
await requireUserSession(event);
}),
],
validate: { query: InboxQuery },
handler: async (event) => {
const { user } = await requireUserSession(event);
return listInbox(user.id);
},
});
Await the guard in a block-bodied onRequest() callback without returning the session. H3 sends a value returned by raw middleware as the response, so middleware: [requireUserSession] can answer a signed-in user with their session. Preserve any policy arguments, such as isAdmin in requireAuthorization(event, isAdmin). If an argument needs validated data or handler-local values, split out the access check that can run earlier. For a method-key endpoint, put a method-specific check in that method's middleware.
The rule knows requireUserSession, requireAuth, requireAuthorization, requireMcpAdminToken, authGuard, and protectRoute. List your own guards in its guards option: ["warn", { guards: ["requireAdmin"] }].
Migration and middleware
| Code | Rule | Severity | H3 |
|---|---|---|---|
| H30001 | h3/migration/no-removed-exports | error | v2 |
| H30002 | h3/migration/prefer-redirect-response | warn | v2 |
| H30003 | h3/migration/prefer-with-base | warn | v2 |
| H30018 | h3/migration/no-ignored-hooks | error | v2 |
| H30019 | h3/migration/no-removed-router-api | error | v2 |
| H30020 | h3/middleware/no-exact-path-use | warn | v2, strict only |
h3/migration/no-removed-exports knows the 19 values and 38 types that H3 1.15 exported and H3 2.0 no longer does, such as send, sendError, MIMES, and the App type. It reports imports, re-exports, and reads through an h3 namespace import, and each diagnostic names the replacement from the migration guide when there is one.
Migrate to H3 v2
Check an H3 1.x server against H3 v2 before changing dependencies:
pnpm dlx vite-doctor migrate . --to h3@2
The report runs the v2 rules as if H3 2.0 were installed and keeps their source changes with the h3 update in each package that declares it. It then lists checks that must wait until v2 is installed, such as replacing createServer(toNodeListener(app)). It does not modify source or package files. h3@2 applies only to packages that declare h3 themselves. In Nitro and Nuxt projects, Nitro provides H3, so use --to nitro@3 or --to nuxt@5, which move H3 to v2.
Moved from Nitro
These rules used to live in the Nitro Rule Pack. They now have H3 ids and codes, with no aliases. Update suppressions and config that name the old ones.
| Old code | Old rule | New code | New rule |
|---|---|---|---|
| NITRO0003 | nitro/request/prefer-assert-method | H30005 | h3/request/prefer-assert-method |
| NITRO0004 | nitro/request/prefer-get-request-ip | H30006 | h3/request/prefer-get-request-ip |
| NITRO0005 | nitro/request/prefer-validated-body | H30007 | h3/request/prefer-validated-body |
| NITRO0006 | nitro/request/prefer-validated-query | H30008 | h3/request/prefer-validated-query |
| NITRO0007 | nitro/request/prefer-validated-router-params | H30009 | h3/request/prefer-validated-router-params |
| NITRO0015 | nitro/h3/no-removed-send | H30001 | h3/migration/no-removed-exports |
| NITRO0016 | nitro/h3/prefer-redirect-response | H30002 | h3/migration/prefer-redirect-response |
| NITRO0017 | nitro/h3/prefer-with-base | H30003 | h3/migration/prefer-with-base |
| NITRO0018 | nitro/h3/no-http-error-masking | H30004 | h3/errors/no-http-error-masking |