Js debug sourcemapurl cross directory

js-debug: cross-directory sourceMappingURL cannot be resolved

Understanding the problem

When the //# sourceMappingURL= comment in a compiled JavaScript file points outside the directory tree covered by remoteRoot/localRoot, js-debug silently fails to load the source map via the CDP path. Breakpoints remain unverified (grey dot) and the call stack shows line numbers in index.js instead of the original TypeScript source.

Understanding the layout that triggers the bug

The RSG 2.0 SDK build pipeline produces two output trees:

dist-dev/
  bundle/
    source/
      compiled/
        index.js          ← esbuild output  (//# sourceMappingURL=index.js.map)
        index.js.map      ← source map
  pkg-dir/
    source/
      compiled/
        index.js          ← copy for device (deep relative sourceMappingURL)

The pkg-dir folder is the clean copy that the build deploys to the Roku device. The bundle folder contains all build artifacts (including the source map, which you must not deploy to the device).

Because the map lives only in bundle/ but the JS copy lives in pkg-dir/, the copy's //# sourceMappingURL comment points across trees:

//# sourceMappingURL=../../../bundle/source/compiled/index.js.map

This is a correct relative path on disk, but js-debug cannot resolve it.

Stripping sourceMappingURL from the pkg-dir copy (workaround A, current approach)

To fix this problem, remove the //# sourceMappingURL= comment from the JavaScript file that the build copies to pkg-dir. js-debug then falls through to the outFiles-based lookup, reads bundle/source/compiled/index.js (which has the simple co-located //# sourceMappingURL=index.js.map), loads the source map through the CDP path, and registers all TypeScript sources correctly.

The trace shows the following effects:

  • The Debugger.scriptParsed event arrives with sourceMapURL: "" (or without the field).
  • js-debug looks up the script through outFiles and finds bundle/source/compiled/index.js.
  • The //# sourceMappingURL=index.js.map comment resolves to bundle/source/compiled/index.js.map.
  • All TypeScript sources get runtime.sourcecreate entries, which show as red dots.

You should use this approach because js-debug does not support multi-prefix remote paths.


Did this page help you?