From be2fde6a85a71ee30d4433a5b486d7e73f9a0f00 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 8 Sep 2025 17:59:54 +0200 Subject: [PATCH] fix(vite): silence optional export warnings (#3360) Seems like vite is overly strict when accessing optional namespaced module properties. The code is perfectly fine, so silence these warnings. --- packages/plugin-vite/src/mod.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/plugin-vite/src/mod.ts b/packages/plugin-vite/src/mod.ts index 28bc41af..5fd19188 100644 --- a/packages/plugin-vite/src/mod.ts +++ b/packages/plugin-vite/src/mod.ts @@ -118,6 +118,23 @@ export function fresh(config?: FreshViteConfig): Plugin[] { if (warning.code === "MODULE_LEVEL_DIRECTIVE") { return; } + + // Ignore optional export errors + if ( + warning.code === "MISSING_EXPORT" && + warning.id?.startsWith("\0fresh-route::") + ) { + return; + } + + // Ignore commonjs optional exports + if ( + warning.code === "MISSING_EXPORT" && + warning.message.includes("__require") + ) { + return; + } + return handler(warning); }, input: {