What versions & operating system are you using?
System:
OS: macOS Darwin 25.2.0 (arm64)
Node: v22.x
npmPackages:
@cloudflare/vite-plugin: 1.25.5
vite: npm:@voidzero-dev/vite-plus-core@0.0.0-g0fd4d06d.20260225-1306 (reports as vite 8.0.0-beta.15)
wrangler: 4.68.1
Please provide a minimal reproduction
Use @cloudflare/vite-plugin with @voidzero-dev/vite-plus-core (vite+), which preserves //# sourceMappingURL=... comments in SSR-transformed module output.
Describe the Bug
The runInlinedModule function in runner-worker.js wraps transformed module code in an async arrow function using a template literal:
const code = `"use strict";async (${Object.keys(context).join(",")})=>{${transformed}}`;
When the transformed code ends with a single-line comment like //# sourceMappingURL=next_link.js.map, the closing } of the arrow function gets absorbed into the comment:
"use strict";async (...)=>{...//# sourceMappingURL=next_link.js.map}
// ^ this } is part of the comment
This results in an unclosed arrow function body and throws:
SyntaxError: Unexpected end of input
at Object.runInlinedModule (workers/runner-worker.js:1314:35)
at CustomModuleRunner.directRequest (workers/runner-worker.js:1166:80)
at CustomModuleRunner.cachedRequest (workers/runner-worker.js:1084:73)
Standard vite strips sourceMappingURL comments from SSR-transformed output, so this doesn't surface there. However, vite-plus-core (vite+) preserves them, triggering this bug.
Fix
Add a newline before the closing brace so it can never be swallowed by a trailing // comment:
- const code = `"use strict";async (${Object.keys(context).join(",")})=>{${transformed}}`;
+ const code = `"use strict";async (${Object.keys(context).join(",")})=>{${transformed}\n}`;
This is a safe, backwards-compatible change — the newline is harmless when there is no trailing comment.
What versions & operating system are you using?
Please provide a minimal reproduction
Use
@cloudflare/vite-pluginwith@voidzero-dev/vite-plus-core(vite+), which preserves//# sourceMappingURL=...comments in SSR-transformed module output.Describe the Bug
The
runInlinedModulefunction inrunner-worker.jswraps transformed module code in an async arrow function using a template literal:When the
transformedcode ends with a single-line comment like//# sourceMappingURL=next_link.js.map, the closing}of the arrow function gets absorbed into the comment:This results in an unclosed arrow function body and throws:
Standard vite strips
sourceMappingURLcomments from SSR-transformed output, so this doesn't surface there. However,vite-plus-core(vite+) preserves them, triggering this bug.Fix
Add a newline before the closing brace so it can never be swallowed by a trailing
//comment:This is a safe, backwards-compatible change — the newline is harmless when there is no trailing comment.