Skip to content

fix(register): always inline source maps in auto mode so debuggers work#1062

Merged
Brooooooklyn merged 1 commit into
masterfrom
fix/debugger-inline-sourcemap-1059
Jul 18, 2026
Merged

fix(register): always inline source maps in auto mode so debuggers work#1062
Brooooooklyn merged 1 commit into
masterfrom
fix/debugger-inline-sourcemap-1059

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Problem

Fixes #1059 — after upgrading to @swc-node/register 1.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:

getSourceMapMode() "auto":
  process.sourceMapsEnabled ? { inline: true,  store: false }   // needs --enable-source-maps
                            : { inline: false, store: true }    // DEFAULT — no inline map

process.sourceMapsEnabled is false by default (only true with --enable-source-maps). Debuggers — VS Code, node --inspect — normally run without that flag, so auto mode picks store-only: it populates SourcemapMap for @swc-node/sourcemap-support to rewrite Error.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 rewrites Error.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.stack stays correct via @swc-node/sourcemap-support, without retaining a duplicate map when Node already handles stack traces):

-return process.sourceMapsEnabled ? { inline: true, store: false } : { inline: false, store: true }
+return process.sourceMapsEnabled ? { inline: true, store: false } : { inline: true,  store: true }

This restores the 1.11.1 behavior of always emitting an inline map. The explicit inline / store / none env modes (SWC_NODE_SOURCE_MAP_MODE) are unchanged.

Verification

  • New regression test in register-runtime-tuning.spec.ts forces process.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.
  • Existing sourcemap integration test (correct stack-trace line numbers, Source maps broken since versions 1.10.1 (up to and including latest 1.10.9) #848/Incorrect stack traces with inline sourceMaps #861) still passes — store remains on when native maps are off.
  • End-to-end: with sourceMap: true and 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

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
@Brooooooklyn
Brooooooklyn merged commit 986094d into master Jul 18, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/debugger-inline-sourcemap-1059 branch July 18, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Debugger stopped working after 1.12.0

1 participant