-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix(vite-node): unable to handle errors where sourcemap mapping empty #8071
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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/jsdom@26.1.0/node_modules/jsdom/lib/jsdom/virtual-console.js:29:53 ❯ module.exports node_modules/.pnpm/jsdom@26.1.0/node_modules/jsdom/lib/jsdom/browser/not-implemented.js:12:26 ❯ HTMLAudioElementImpl.load node_modules/.pnpm/jsdom@26.1.0/node_modules/jsdom/lib/jsdom/living/nodes/HTMLMediaElement-impl.js:112:5 ❯ HTMLAudioElement.load node_modules/.pnpm/jsdom@26.1.0/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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: https://github.com/blake-newman/vitest-dev-vitest-se4padzq Turns out it's specific to when using TSX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:.