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({