The Problem
When working with Nuxt server routes, developers frequently need to use h3 types like H3Event, H3Error, and EventHandler. However, IDE auto-import suggestions weren’t working for these types, creating friction in the developer experience.
The root cause was that Nitro’s auto-import configuration intentionally filters out uppercase exports using a regex pattern (!/^[A-Z]/.test(n)). While h3 is a transitive dependency of Nuxt/Nitro, TypeScript could resolve imports like import type { H3Event } from "h3", but IDEs wouldn’t offer auto-import suggestions unless developers manually added h3 as a direct project dependency.
This was particularly painful for common use cases:
// Developers had to manually import these types
import type { H3Event, EventHandler } from 'h3'
export default defineEventHandler((event: H3Event) => {
// Handler logic
})
Adding h3 as a devDependency was a workaround, but it proved insufficient in pnpm workspaces and added unnecessary friction—requiring a direct dependency solely for editor ergonomics.
The Solution
I added explicit h3 type imports to Nitro’s imports presets configuration, bypassing the uppercase export filter. The fix distinguishes between runtime values and type-only imports:
Runtime imports (these are classes that exist at runtime):
H3EventH3Error
Type-only imports (pure TypeScript types):
EventHandlerEventHandlerRequestEventHandlerResponseEventHandlerObjectH3EventContext
The implementation adds a presets array to the Nitro imports configuration:
imports: {
presets: [
{
from: 'h3',
imports: ['H3Event', 'H3Error'],
},
{
from: 'h3',
imports: [
'EventHandler',
'EventHandlerRequest',
'EventHandlerResponse',
'EventHandlerObject',
'H3EventContext',
],
type: true,
},
] as const,
// ... existing autoImport and dirs config
}
During code review, CodeRabbit suggested applying as const to the entire presets array rather than individual imports for improved type inference—a suggestion I implemented in subsequent commits to follow codebase conventions.
Files Changed
| File | Purpose |
|---|---|
packages/nitro-server/src/index.ts | Added h3 type presets to Nitro’s imports configuration |
docs/2.directory-structure/1.server.md | Documentation updates (removed per review feedback) |
Timeline
| Date | Action |
|---|---|
| 2025-12-15 | Issue #33889 reported by jmroon |
| 2026-01-05 | Analyzed Nitro’s import filtering logic and identified the uppercase export filter |
| 2026-01-05 | Implemented fix and verified with playground and tests |
| 2026-01-06 | PR #34035 opened |
| 2026-01-06 | Applied as const to entire presets array per codebase convention |
| 2026-01-06 | Awaiting review from @danielroe (code owner) |
| 2026-01-14 | PR merged by @danielroe, included in v4.3.0 |