From c760b3b546c15660476da2aec408a4c930d18ba4 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Tue, 7 Apr 2026 12:21:23 +0800 Subject: [PATCH 1/2] fix: silent IMPORT_IS_UNDEFINED for proxy.ts --- packages/vinext/src/index.ts | 16 +++++++++++++ tests/pages-router.test.ts | 45 ++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/packages/vinext/src/index.ts b/packages/vinext/src/index.ts index 6f163909..9a113930 100644 --- a/packages/vinext/src/index.ts +++ b/packages/vinext/src/index.ts @@ -1472,6 +1472,22 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] { ) { return; } + // proxy.ts / middleware.ts may export either a named handler + // or default export. The generated virtual entries probe both + // forms and validate at runtime, which can trigger noisy + // IMPORT_IS_UNDEFINED warnings when only one form exists. + if ( + warning.code === "IMPORT_IS_UNDEFINED" && + warning.message?.includes("Import `default` will always be undefined") && + (warning.message?.includes("proxy.ts") || + warning.message?.includes("proxy.js") || + warning.message?.includes("middleware.ts") || + warning.message?.includes("middleware.js")) && + (warning.message?.includes("virtual:vinext-rsc-entry") || + warning.message?.includes("virtual:vinext-server-entry")) + ) { + return; + } if (userOnwarn) { userOnwarn(warning, defaultHandler); } else { diff --git a/tests/pages-router.test.ts b/tests/pages-router.test.ts index 4e0b816d..e17f7d9d 100644 --- a/tests/pages-router.test.ts +++ b/tests/pages-router.test.ts @@ -1444,6 +1444,51 @@ describe("Plugin config", () => { expect(defaultHandler).toHaveBeenCalledWith(otherWarning); }); + it("suppresses IMPORT_IS_UNDEFINED noise for generated proxy/middleware default fallbacks", async () => { + const plugins = vinext() as any[]; + const configPlugin = plugins.find((p) => p.name === "vinext:config"); + expect(configPlugin).toBeDefined(); + + const result = await configPlugin.config({ root: FIXTURE_DIR, plugins: [] }); + + expect(result.build).toBeDefined(); + const bundlerOptions = getBuildBundlerOptions(result); + expect(bundlerOptions).toBeDefined(); + expect(bundlerOptions.onwarn).toBeDefined(); + + const defaultHandler = vi.fn(); + + bundlerOptions.onwarn( + { + code: "IMPORT_IS_UNDEFINED", + message: + "[IMPORT_IS_UNDEFINED] Warning: Import `default` will always be undefined because there is no matching export in 'proxy.ts'\\n ╭─[ \\0virtual:vinext-rsc-entry:2632:34 ]", + }, + defaultHandler, + ); + expect(defaultHandler).not.toHaveBeenCalled(); + + bundlerOptions.onwarn( + { + code: "IMPORT_IS_UNDEFINED", + message: + "[IMPORT_IS_UNDEFINED] Warning: Import `default` will always be undefined because there is no matching export in 'middleware.ts'\\n ╭─[ \\0virtual:vinext-server-entry:168:34 ]", + }, + defaultHandler, + ); + expect(defaultHandler).not.toHaveBeenCalled(); + + bundlerOptions.onwarn( + { + code: "IMPORT_IS_UNDEFINED", + message: + "[IMPORT_IS_UNDEFINED] Warning: Import `default` will always be undefined because there is no matching export in 'some-user-file.ts'", + }, + defaultHandler, + ); + expect(defaultHandler).toHaveBeenCalledTimes(1); + }); + it("preserves user-supplied build.rollupOptions.onwarn", async () => { const plugins = vinext() as any[]; const configPlugin = plugins.find((p) => p.name === "vinext:config"); From 98faebcdfed894bc766fc24a3979007296330e32 Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Wed, 8 Apr 2026 09:22:09 +0800 Subject: [PATCH 2/2] tweaks --- packages/vinext/src/index.ts | 11 ++++++----- tests/pages-router.test.ts | 32 +++++++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/packages/vinext/src/index.ts b/packages/vinext/src/index.ts index 9a113930..b84ff568 100644 --- a/packages/vinext/src/index.ts +++ b/packages/vinext/src/index.ts @@ -1476,13 +1476,14 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] { // or default export. The generated virtual entries probe both // forms and validate at runtime, which can trigger noisy // IMPORT_IS_UNDEFINED warnings when only one form exists. + // Match any file extension because findMiddlewareFile() scans + // all configured pageExtensions, not just .ts/.js. if ( warning.code === "IMPORT_IS_UNDEFINED" && - warning.message?.includes("Import `default` will always be undefined") && - (warning.message?.includes("proxy.ts") || - warning.message?.includes("proxy.js") || - warning.message?.includes("middleware.ts") || - warning.message?.includes("middleware.js")) && + /Import `(?:default|proxy|middleware)` will always be undefined/.test( + warning.message ?? "", + ) && + /\b(?:proxy|middleware)\.\w+\b/.test(warning.message ?? "") && (warning.message?.includes("virtual:vinext-rsc-entry") || warning.message?.includes("virtual:vinext-server-entry")) ) { diff --git a/tests/pages-router.test.ts b/tests/pages-router.test.ts index e17f7d9d..c437ad13 100644 --- a/tests/pages-router.test.ts +++ b/tests/pages-router.test.ts @@ -1444,7 +1444,7 @@ describe("Plugin config", () => { expect(defaultHandler).toHaveBeenCalledWith(otherWarning); }); - it("suppresses IMPORT_IS_UNDEFINED noise for generated proxy/middleware default fallbacks", async () => { + it("suppresses IMPORT_IS_UNDEFINED noise for generated proxy/middleware fallback probes", async () => { const plugins = vinext() as any[]; const configPlugin = plugins.find((p) => p.name === "vinext:config"); expect(configPlugin).toBeDefined(); @@ -1478,6 +1478,26 @@ describe("Plugin config", () => { ); expect(defaultHandler).not.toHaveBeenCalled(); + bundlerOptions.onwarn( + { + code: "IMPORT_IS_UNDEFINED", + message: + "[IMPORT_IS_UNDEFINED] Warning: Import `proxy` will always be undefined because there is no matching export in 'proxy.tsx'\\n ╭─[ \\0virtual:vinext-rsc-entry:2632:34 ]", + }, + defaultHandler, + ); + expect(defaultHandler).not.toHaveBeenCalled(); + + bundlerOptions.onwarn( + { + code: "IMPORT_IS_UNDEFINED", + message: + "[IMPORT_IS_UNDEFINED] Warning: Import `middleware` will always be undefined because there is no matching export in 'middleware.jsx'\\n ╭─[ \\0virtual:vinext-server-entry:168:34 ]", + }, + defaultHandler, + ); + expect(defaultHandler).not.toHaveBeenCalled(); + bundlerOptions.onwarn( { code: "IMPORT_IS_UNDEFINED", @@ -1487,6 +1507,16 @@ describe("Plugin config", () => { defaultHandler, ); expect(defaultHandler).toHaveBeenCalledTimes(1); + + bundlerOptions.onwarn( + { + code: "IMPORT_IS_UNDEFINED", + message: + "[IMPORT_IS_UNDEFINED] Warning: Import `proxy` will always be undefined because there is no matching export in 'some-user-file.ts'", + }, + defaultHandler, + ); + expect(defaultHandler).toHaveBeenCalledTimes(2); }); it("preserves user-supplied build.rollupOptions.onwarn", async () => {