Nitro · Routing

NITRO0031Don't let two route files resolve to the same route

Reports a route file when another file in the same api/ or routes/ directory resolves to the same route, method, and environment, and Nitro keeps the other one. A method-less handler next to a method handler is not reported, and neither are overrides across Nuxt layers. Unresolved layers, environment overrides, custom scan directories or suffixes, and ignore options are evidence gaps.

Why it happens

Nitro registers the first scanned file for each route, method, and environment and silently drops the rest. Two files such as api/users.ts and api/users/index.ts both serve /api/users, so one of them never runs and edits to it have no effect.

Fix

Delete or rename one of the files. Keep one handler per route, or give each file a method suffix when they handle different methods.

Example

Keep one file per route

Before

// server/api/users.ts
export default defineEventHandler(() => listUsers())

// server/api/users/index.ts
export default defineEventHandler(() => listActiveUsers())

After

// server/api/users.get.ts
export default defineEventHandler(() => listUsers())

// server/api/users.post.ts
export default defineEventHandler((event) => createUser(event))

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/no-shadowed-file-handler
Copyright © 2026