Skip to content

Configured handler aliases depend on insertion order #4980

Closed

Description

@clean99

Environment

Nitro 3.0.261029-rc, Node.js 24.16.0. Also reproduced from main at f794c37.

Reproduction

Run in an empty directory:

npm init -y
npm install [email protected]
node --input-type=module <<'JS'
import { loadOptions } from 'nitro/builder';
import { relative } from 'node:path';

for (const reverse of [false, true]) {
  const entries = [['#api', './api'], ['#api-admin', './admin']];
  const options = await loadOptions({
    rootDir: process.cwd(),
    preset: 'node',
    builder: false,
    serverEntry: false,
    renderer: false,
    alias: Object.fromEntries(reverse ? entries.reverse() : entries),
    routes: { '/test': '#api-admin/handler.ts' },
  }, {
    dotenv: false,
    c12: { configFile: '__empty__', rcFile: false, globalRc: false, packageJson: false },
  });
  console.log(reverse, relative(process.cwd(), options.routes['/test'].handler));
}
JS

Describe the bug

A project with separate #api and #api-admin directories resolves /test to api-admin/handler.ts when #api comes first. Reversing the aliases resolves the same handler to admin/handler.ts.

Expected: both orders resolve to admin/handler.ts. When only that file exists, the incorrect path also prevents the server build from resolving the handler.

The same order dependence occurs with #api and #api/admin.

Logs

false api-admin/handler.ts
true admin/handler.ts

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions