Skip to content

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

Conversation

blake-newman
Copy link
Contributor

@blake-newman blake-newman commented Jun 2, 2025

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.


Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

@blake-newman blake-newman force-pushed the blake.newman/console-error-source-map branch from 4a8c0a9 to f1d1ca8 Compare June 2, 2025 13:38
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.
@blake-newman blake-newman force-pushed the blake.newman/console-error-source-map branch from f1d1ca8 to 0634378 Compare June 2, 2025 13:39
@blake-newman
Copy link
Contributor Author

Looks like this could be related:

#5380

Copy link
Contributor

@hi-ogawa hi-ogawa left a 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.

@blake-newman
Copy link
Contributor Author

blake-newman commented Jun 4, 2025

@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

Copy link
Contributor

@hi-ogawa hi-ogawa left a 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).

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.

3 participants