fix(register): always inline source maps in auto mode so debuggers work#1062
Merged
Conversation
The auto source-map mode introduced in 1.12.0 only inlined the map into the emitted code when `process.sourceMapsEnabled` was true (i.e. Node was started with `--enable-source-maps`). Otherwise it fell back to store-only mode, which populates SourcemapMap for `@swc-node/sourcemap-support` to rewrite `Error.stack`, but emits no inline `//# sourceMappingURL=`. The V8 inspector reads that inline map off the running code to bind breakpoints, and it does so regardless of `--enable-source-maps`. With no inline map, debuggers (VS Code, `node --inspect`) stopped binding breakpoints or landed on the wrong line. This is the 1.12.0 regression in #1059. Auto mode now always inlines the map, and additionally stores it only when native source maps are off (so stack traces stay correct without retaining a duplicate map when Node already handles them). This restores the 1.11.1 behavior of always emitting an inline map. The `inline`/`store`/`none` env modes are unchanged. Closes #1059 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LXSDomd3mGu4SL4TJ9q6T2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #1059 — after upgrading to
@swc-node/register1.12.0, the Node debugger stopped binding breakpoints (or landed on the wrong line). Downgrading to 1.11.1 fixed it.Root cause
The auto source-map mode added in 1.12.0 decides whether to inline the map based on
process.sourceMapsEnabled:process.sourceMapsEnabledisfalseby default (only true with--enable-source-maps). Debuggers — VS Code,node --inspect— normally run without that flag, so auto mode picks store-only: it populatesSourcemapMapfor@swc-node/sourcemap-supportto rewriteError.stack, but emits no inline//# sourceMappingURL=.The V8 inspector reads the inline map off the running code to bind breakpoints, and it does so regardless of
--enable-source-maps(that flag only governs how Node rewritesError.stack). With no inline map, breakpoints have nothing to bind to.In 1.11.1 the inline map was emitted unconditionally, so the debugger always worked.
Fix
Auto mode now always inlines the map, and additionally stores it only when native source maps are off (so
Error.stackstays correct via@swc-node/sourcemap-support, without retaining a duplicate map when Node already handles stack traces):This restores the 1.11.1 behavior of always emitting an inline map. The explicit
inline/store/noneenv modes (SWC_NODE_SOURCE_MAP_MODE) are unchanged.Verification
register-runtime-tuning.spec.tsforcesprocess.setSourceMapsEnabled(false)(the debugger-breaking condition) and asserts the emitted code carries an inline map and stores it. It fails on the old code, passes on the fix.storeremains on when native maps are off.sourceMap: trueand no--enable-source-maps, the emitted code now contains an inline map and a thrown error reports the correct source line.🤖 Generated with Claude Code
https://claude.ai/code/session_01LXSDomd3mGu4SL4TJ9q6T2