Skip to content

fix(node): handle dependency stack traces with external source maps in non-browser mode#9047

Closed
iclectic wants to merge 7 commits intovitest-dev:mainfrom
iclectic:fix/non-browser-external-sourcemaps
Closed

fix(node): handle dependency stack traces with external source maps in non-browser mode#9047
iclectic wants to merge 7 commits intovitest-dev:mainfrom
iclectic:fix/non-browser-external-sourcemaps

Conversation

@iclectic
Copy link
Copy Markdown
Contributor

Description

Resolves #9003

Changes

  • Added the getSourceMap option to parseErrorStacktrace calls in non-browser mode
  • Introduced a new retrieveSourceMapURL helper to extract source map URLs from code
  • Implemented logic to load external map files from disk (including those generated in build output directories)
  • Improved error handling so missing source maps are caught and ignored safely

Tests

  • Added complete test coverage for external source maps in non-browser mode
  • All new tests pass across threads, forks, and vmThreads
  • Confirmed that the full existing test suite still passes (191 files, 1981 tests)

Related

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.
  • Please check Allow edits by maintainers to make review process faster. Note that this option is not available for repositories that are owned by Github organizations.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • N/A - This is a bug fix that restores expected behavior, not new functionality.

Changesets

  • PR title uses fix: prefix for automatic changelog generation.

…n non-browser mode

Fixes #9003 (non-browser mode)

The previous fix in 57ea647 only addressed browser mode. This PR extends
the fix to non-browser mode (threads, forks, vmThreads) by:

- Adding getSourceMap option to non-browser parseErrorStacktrace calls
- Creating retrieveSourceMapURL helper to extract source map URLs
- Adding logic to read external source map files from disk
- Handling missing source maps gracefully with try-catch
- Adding comprehensive tests across all execution modes
@netlify
Copy link
Copy Markdown

netlify bot commented Nov 17, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit cda1bc7
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/691baf3405c6df0008fe5644
😎 Deploy Preview https://deploy-preview-9047--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

}
}

function retrieveSourceMapURL(source: string): string | null {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we merge this PR, this function will be defined 4 times. Can't you just export it from some util and use it?

@iclectic
Copy link
Copy Markdown
Contributor Author

I have incorporated the feedback by extracting the retrieveSourceMapURL function into a shared utility within @vitest/utils/source-map.

Summary of Updates

  • Moved the retrieveSourceMapURL logic out of the four duplicated locations and placed it into a central shared utility.
  • Updated all relevant imports across the internal modules that relied on this function.
  • Confirmed that all tests pass locally, including the new external source map test.
  • Lint checks pass and the build completes successfully.

About the CI Failures

  • The current CI errors do not appear to be caused by this pull request:
  • Browser test failures
  • The failures relate to the browser test runner losing its connection.
  • This change only affects source map handling in non-browser environments.
  • These look like infrastructure or WebSocket issues.

Dependency trust error

  • The ERR_PNPM_TRUST_DOWNGRADE issue for @wdio/types@9.20.0 is affecting multiple PRs.
  • This is a dependency-level problem unrelated to the changes in this update.

Everything introduced in this PR has been validated locally and behaves as expected.
Happy to make any additional adjustments if needed.

@iclectic iclectic requested a review from sheremet-va November 19, 2025 00:23
expect(stderr).not.toContain('FAIL')
})

test('should parse stack traces with external source maps in error output', async () => {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how this test case is testing external library's source map? It looks like it's importing as user's file via import './bundled-lib.js'.

@iclectic iclectic closed this by deleting the head repository Dec 31, 2025
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.

stack trace without source maps of external modules

3 participants