From 3228012f1f22067fbd7a120ceb05d2893db91d2b Mon Sep 17 00:00:00 2001 From: Carson Rodrigues Date: Thu, 2 Jul 2026 11:03:30 +0530 Subject: [PATCH] fix(start-plugin-core): keep import-protection virtual ids resolvable in server-fn compiler In build mode, the server-fn compiler's resolveId ran every resolved id through cleanId(), which strips the leading \0 that marks a Rollup virtual module. For import-protection's own virtual ids (e.g. mock-edge), that broke the subsequent this.load(): its load handler matches on the \0-prefixed matchers, so the stripped id fell through to vite:load-fallback, which fs.readFile()d the bare id and threw 'Could not load tanstack-start-import-protection:mock-edge:...: ENOENT'. Preserve the \0 prefix for import-protection ids so loadModule routes them to the correct load handler; other ids are still cleaned as before. Fixes #7725 --- .../src/vite/start-compiler-plugin/plugin.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts b/packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts index 6309b76eb2..ce89a0ef61 100644 --- a/packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts +++ b/packages/start-plugin-core/src/vite/start-compiler-plugin/plugin.ts @@ -364,6 +364,15 @@ export function startCompilerPlugin( if (r) { if (!r.external) { + // Keep import-protection's own virtual ids (e.g. mock-edge) + // `\0`-prefixed: `loadModule`/`this.load()` routes them to the + // import-protection `load` handler by matching on the `\0` + // prefix. Stripping it via cleanId() makes the load fall + // through to vite:load-fallback, which fs.readFile()s the + // bare id and throws ENOENT in build mode (#7725). + if (r.id.startsWith('\0tanstack-start-import-protection:')) { + return r.id + } return cleanId(r.id) } }