Nitro · Routing

NITRO0020Default-export a handler from every Nitro route file

Requires every file in a statically resolved Nitro api/ or routes/ directory to default-export a handler and keep helpers out of the route tree. The rule stays disabled for ambiguous configs or configured scanDirs, apiDir, or routesDir until resolved Runtime Evidence is available.

Why it happens

Nitro registers every file under server/api and server/routes as a route. A helper module placed there becomes a public URL with no working handler, and other routes that import it pull in a route module.

Fix

Default-export a handler from each route file. Move shared helpers to server/utils/, where Nitro 2 and Nuxt auto-import them, and keep only type exports next to the handler.

Example

Move route helpers to server/utils

Before

// server/api/_db.ts
export function getDb() {
  return drizzle(useRuntimeConfig().databaseUrl)
}

After

// server/utils/db.ts
export function getDb() {
  return drizzle(useRuntimeConfig().databaseUrl)
}

// server/api/users.get.ts
export default defineEventHandler(() => getDb().select().from(users))

Verify the fix

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

pnpm vite-doctor . --framework nitro --rules nitro/routes/require-default-handler
Copyright © 2026