Describe the bug
When a source file has specific string that matches the MODULE_RUNNER_SOURCEMAPPING_REGEXP, getModuleSourceMapById will pick wrong source map URL and can fail.
|
const MODULE_RUNNER_SOURCEMAPPING_REGEXP = new RegExp( |
|
`//# ${SOURCEMAPPING_URL}=data:application/json;base64,(.+)`, |
|
) |
throw lazyDOMException('Invalid character', 'InvalidCharacterError');
^
DOMException [InvalidCharacterError]: Invalid character
at atob (node:buffer:1302:13)
at EvaluatedModules.getModuleSourceMapById (file:///Users/ari/Git/repros/module-runner/node_modules/.pnpm/vite@7.0.6/node_modules/vite/dist/node/module-runner.js:286:59)
at file:///Users/ari/Git/repros/module-runner/index.mjs:24:31
In the reproduction, this will fix the crash:
- const text = "//# sourceMappingURL=data:application/json;base64,\${encoded}";
+ const text = "//# sourceMappingURL_ANYTHING=data:application/json;base64,\${encoded}";
Reproduction
https://stackblitz.com/~/edit/node-eolunju1?file=index.js
Steps to reproduce
npm i; node index.js
System Info
System:
OS: macOS 15.5
CPU: (8) arm64 Apple M2
Memory: 121.16 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 22.17.0 - ~/.nvm/versions/node/v22.17.0/bin/node
npm: 10.9.2 - ~/.nvm/versions/node/v22.17.0/bin/npm
pnpm: 8.15.9 - ~/.nvm/versions/node/v22.17.0/bin/pnpm
bun: 1.2.16 - ~/.bun/bin/bun
Browsers:
Brave Browser: 131.1.73.101
Chrome: 138.0.7204.184
Safari: 18.5
npmPackages:
vite: ^7.0.6 => 7.0.6
Used Package Manager
npm
Logs
No response
Validations
Describe the bug
When a source file has specific string that matches the
MODULE_RUNNER_SOURCEMAPPING_REGEXP,getModuleSourceMapByIdwill pick wrong source map URL and can fail.vite/packages/vite/src/module-runner/evaluatedModules.ts
Lines 7 to 9 in 3c961ec
In the reproduction, this will fix the crash:
Reproduction
https://stackblitz.com/~/edit/node-eolunju1?file=index.js
Steps to reproduce
npm i; node index.jsSystem Info
System: OS: macOS 15.5 CPU: (8) arm64 Apple M2 Memory: 121.16 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 22.17.0 - ~/.nvm/versions/node/v22.17.0/bin/node npm: 10.9.2 - ~/.nvm/versions/node/v22.17.0/bin/npm pnpm: 8.15.9 - ~/.nvm/versions/node/v22.17.0/bin/pnpm bun: 1.2.16 - ~/.bun/bin/bun Browsers: Brave Browser: 131.1.73.101 Chrome: 138.0.7204.184 Safari: 18.5 npmPackages: vite: ^7.0.6 => 7.0.6Used Package Manager
npm
Logs
No response
Validations