Skip to content

Routing virtual modules interpolate raw handler paths, breaking late-registered handlers on Windows #4907

Closed

Description

@pi0x

The #nitro/virtual/routing and #nitro/virtual/routing-meta templates interpolate h.handler directly into string literals:

`import ${h._importHash} from "${h.handler}";`
`const ${h._importHash} = h3.defineLazyEventHandler(() => import("${h.handler}"));`
`import ${h._importHash}Meta from "${h.handler}?meta";`

Handler paths are only normalized by resolveNitroPath() while options are resolved. A handler pushed to nitro.options.handlers afterwards (from a module or hook, followed by nitro.routing.sync()) keeps whatever path it was given. On Windows a node:path path such as C:\app\.nitro\workflow\handler.mjs ends up as "C:\app\.nitro\workflow\handler.mjs" in generated code. The backslashes are read as escape sequences, so the specifier is silently mangled or the module fails to parse (\x, \u).

Minimal shape:

nitro.options.handlers.push({ route: "/hello", handler: join(dir, "hello.mjs") });
nitro.routing.sync();

Works on POSIX and breaks on Windows. Emitting the specifier with JSON.stringify() after normalizing it (forward slashes, or a file:// URL for drive-letter paths), or normalizing handler paths in routing.sync(), would make late-registered handlers behave like config-time ones.

eve works around this with a transform on both virtual ids that rewrites drive-letter specifiers to file:// URLs (nitro-routing-import-specifier-plugin.ts), and would drop it once Nitro handles this.

Found by reading the generated templates in [email protected]; not reproduced on a Windows machine for this report.

Opened with AI assistance.

Activity

  1. added
    bug
    windows
    on Oct 23, 2026
  2. added theissue type on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwindows

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions