Skip to content

fix(transform): wrap VM errors as host Error with filename context#819

Merged
layershifter merged 6 commits intomainfrom
fix/vm-error-improvements
Mar 13, 2026
Merged

fix(transform): wrap VM errors as host Error with filename context#819
layershifter merged 6 commits intomainfrom
fix/vm-error-improvements

Conversation

@layershifter
Copy link
Member

@layershifter layershifter commented Mar 13, 2026

Summary

  • Re-throw vm.runInContext() errors as proper host Error instances in Module.evaluate(), fixing webpack's NonErrorEmittedError wrapping (VM-context errors fail instanceof Error in the host)
  • Preserve the original stack trace so the offending filename and line are visible
  • Add filename to transformSync error messages
  • Switch webpack-plugin to VM evaluation mode

Test plan

  • nx test transform — 74 tests pass
  • nx test webpack-plugin — 47 tests pass (includes new e2e test asserting the full error trace contains the offending imported file)

🤖 Generated with Claude Code

layershifter and others added 2 commits March 13, 2026 17:10
Wrap vm.runInContext() errors in Module.evaluate() as proper host Error
instances with filename context, fixing NonErrorEmittedError in webpack.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… evaluation mode

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@layershifter layershifter requested a review from a team as a code owner March 13, 2026 16:11
@github-actions
Copy link

github-actions bot commented Mar 13, 2026

📊 Bundle size report

✅ No changes found

layershifter and others added 2 commits March 13, 2026 17:13
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update the VM error test to trigger an error in an imported child module
and verify the child filename appears in both message and stack trace.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@layershifter layershifter force-pushed the fix/vm-error-improvements branch from da6c9ff to 08065c9 Compare March 13, 2026 16:14
- Remove redundant filename prefix from re-thrown VM errors (stack trace
  already contains the filename)
- Use toMatchInlineSnapshot() for error message and stack trace assertions
- Add webpack-plugin e2e test verifying the full error trace includes the
  offending imported file

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@layershifter layershifter enabled auto-merge (squash) March 13, 2026 16:20
…ally

- Replace `replaceAll` with `split/join` for ES2020 compat
- Use `path.resolve(__dirname, '...')` instead of hardcoded regex to
  normalize repo paths, fixing CI where the repo path differs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@layershifter layershifter changed the title fix(transform): improve VM error messages and CJS export handling fix(transform): wrap VM errors as host Error with filename context Mar 13, 2026
@layershifter layershifter merged commit e0f931f into main Mar 13, 2026
4 checks passed
@layershifter layershifter deleted the fix/vm-error-improvements branch March 13, 2026 16:26
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.

2 participants