Skip to content

fix(ssr): encode whitespace in module runner sourceURL - #23513

Open
danielroe wants to merge 2 commits into
vitejs:mainfrom
danielroe:fix/sourceurl-space
Open

danielroe wants to merge 2 commits into
vitejs:mainfrom
danielroe:fix/sourceurl-space

Conversation

@danielroe

@danielroe danielroe commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

I hit this testing Nuxt from a directory whose name contains a space. to be fair, I was trying to get errors (testing nuxt/nuxt#36258).

... and lo and behold, I did! any error thrown from a module evaluated by the module runner loses its file name entirely:

Error: boom from utils
    at boom (eval at runInlinedModule (/…/vite/dist/node/module-runner.js:809:9), <anonymous>:6:8)
    at setup (eval at runInlinedModule (...), <anonymous>:12:3)

the same project at a path without a space shows at boom (/.../app/utils/boom.ts:2:9)

V8 only reads the module id up to the first whitespace character (see scanner source), but we previously just wrote the raw module id after //# sourceURL=

this PR percent-encodes just the whitespace when writing the directive, and decodes it back in the two places that turn a frame's file back into a module id (getRunnerSourceMap in the interceptor, and ssrRewriteStacktrace for ssrFixStacktrace).

I decide to encode rather than pathToFileURL because both lookups key off the raw id, and a file:// sourceURL might need a wider id normalisation.

but you may have a different suggestion 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant