diff --git a/src/rollup/plugins/handlers.ts b/src/rollup/plugins/handlers.ts index 87108a1123..eeabdc7892 100644 --- a/src/rollup/plugins/handlers.ts +++ b/src/rollup/plugins/handlers.ts @@ -93,10 +93,11 @@ ${handlers }, "#nitro-internal-virtual/server-handlers-meta": () => { const handlers = getHandlers(); + const imports = unique(handlers.map((h) => h.handler)); return /* js */ ` - ${handlers + ${imports .map( - (h) => `import ${getImportId(h.handler)}Meta from "${h.handler}?meta";` + (handler) => `import ${getImportId(handler)}Meta from "${handler}?meta";` ) .join("\n")} export const handlersMeta = [ diff --git a/test/fixture/nitro.config.ts b/test/fixture/nitro.config.ts index 63d8eca4cd..c9f35e67d2 100644 --- a/test/fixture/nitro.config.ts +++ b/test/fixture/nitro.config.ts @@ -24,6 +24,10 @@ export default defineNitroConfig({ // @ts-expect-error #2382 method: "GET", }, + { + route: "/api/hello2", + handler: "~/api/hello.ts", + }, ], devProxy: { "/proxy/example": { target: "https://example.com", changeOrigin: true },