fix(vite-node): unable to handle errors where sourcemap mapping empty#8071
Conversation
4a8c0a9 to
f1d1ca8
Compare
vitejs/vite#19226 introduced a change where by empty source mappings are not combined. As such when vitest has an internal error caused such as using jsdom feature that is not implemented which logs an error it tries to map the source map when the mapping is empty which results in an error such as: ``` Cannot read properties of undefined (reading 'map') ❯ VirtualConsole.<anonymous> node_modules/.pnpm/[email protected]/node_modules/jsdom/lib/jsdom/virtual-console.js:29:53 ❯ module.exports node_modules/.pnpm/[email protected]/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:12:26 ❯ HTMLAudioElementImpl.load node_modules/.pnpm/[email protected]/node_modules/jsdom/lib/jsdom/living/nodes/HTMLMediaElement-impl.js:112:5 ❯ HTMLAudioElement.load node_modules/.pnpm/[email protected]/node_modules/jsdom/lib/jsdom/living/generated/HTMLMediaElement.js:109:34 ``` When the error originates from a file without source mapping such as `x.vue` it errors instead of logging original error.
f1d1ca8 to
0634378
Compare
|
Looks like this could be related: |
hi-ogawa
left a comment
There was a problem hiding this comment.
Good catch. I think I have some idea how this goes wrong, but reproduction would be great 🙏 Is the error happening during new TraceMap({ mappings: '' })?
Also I'm not sure whether we should fix it here or maybe we can change Vite ssrTransform to return more robust map.
|
@hi-ogawa here is reproduction. Sorry took me a while to reproduce myself: Turns out it's specific to when using TSX |
There was a problem hiding this comment.
Thanks for the fix! I added a minimal repro as a test case. The same issue didn't reproduce on Vite SSR / module runner because Vite's handling is internally more robust (e.g. checking "version" in map and also fallback sources ?? [] to avoid undefined.map).
vitejs/vite#19226 introduced a change where by empty source mappings are not combined. As such when vitest has an internal error caused such as using jsdom feature that is not implemented which logs an error it tries to map the source map when the mapping is empty which results in an error such as:
When the error originates from a file without source mapping such as
x.vueit errors instead of logging original error.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
pnpm-lock.yamlunless you introduce a new test example.Tests
pnpm test:ci.Documentation
pnpm run docscommand.Changesets
feat:,fix:,perf:,docs:, orchore:.