From 1bd61ba7b7effdaea3a55c4ed5fd9fed5cf5679e Mon Sep 17 00:00:00 2001 From: Sheraff Date: Sun, 25 Oct 2026 11:07:53 +0100 Subject: [PATCH] fix(start-plugin-core): the Vite host leaves parse errors to the bundler's parser A CommonJS dependency with a top-level `return` is no ES module: the core reports a parse error and leaves the module as it is, and Vite's own parser reports real syntax errors at the user's position (as the Rsbuild loader already did). Flips the Vite row of "a CommonJS dependency with a top-level return builds and keeps its meaning". Co-Authored-By: Claude Fable 5.1 --- packages/start-plugin-core/src/vite/compiler-plugin.ts | 7 +++++++ .../tests/integration/known-bugs-start-compiler.test.ts | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/start-plugin-core/src/vite/compiler-plugin.ts b/packages/start-plugin-core/src/vite/compiler-plugin.ts index 4d90d02795..1b3e085c64 100644 --- a/packages/start-plugin-core/src/vite/compiler-plugin.ts +++ b/packages/start-plugin-core/src/vite/compiler-plugin.ts @@ -605,6 +605,13 @@ export function startCompilerPlugin( } const source = new SourceText(code) for (const d of diagnostics) { + if (d.by === 'parse') { + // the module is left as it is: the bundler's own parser reports a + // syntax error at the user's position, and a script no ESM parse + // accepts (a CommonJS dependency with a top-level `return`) is + // nothing the compiler touches (J4.16, ยง5.15) + continue + } if (d.severity === 'error') { const loc = locationOf(source, filePath, d) ctx.error({ diff --git a/packages/start-plugin-core/tests/integration/known-bugs-start-compiler.test.ts b/packages/start-plugin-core/tests/integration/known-bugs-start-compiler.test.ts index 2421462cf2..5689e8cd74 100644 --- a/packages/start-plugin-core/tests/integration/known-bugs-start-compiler.test.ts +++ b/packages/start-plugin-core/tests/integration/known-bugs-start-compiler.test.ts @@ -618,9 +618,9 @@ ${callByIdExports}`, // Impact: an app with such a dependency does not build (Vite: when client // code imports it, or SSR code with `noExternal`; Rsbuild: client or SSR). // SPEC J4.16. These apps replace the in-process compiler pin of this - // name. - // (Rsbuild compiles only modules whose plan needs it; Vite's row stays pinned) - ;(bundler === 'rsbuild' ? test : test.fails)( + // name. (Both hosts leave a module the compiler cannot parse as an ES + // module to the bundler's own parser.) + test( 'a CommonJS dependency with a top-level return builds and keeps its meaning', async () => { const { client, ssr } = await buildStart({