node icon indicating copy to clipboard operation
node copied to clipboard

source maps are not working when debugging with chrome

Open yanivefraim opened this issue 10 years ago • 71 comments

  • Version: 6.3.1 +
  • Platform: OSX

I am debugging my mocha tests using native node debugger, using the following command:

/usr/local/bin/node --debug-brk --inspect=9444 --expose_debug_as=v8debug /Users/yanivef/Documents/projects/node-debug-example/node_modules/mocha/bin/_mocha --require babel-register --timeout 0 --ui bdd test/**/*.spec.js

Debugger works great, but I cannot make source maps to work.

I created a small simple example here.

Just clone + npm i + npm run test-debug. You'll see that when opening the address from command line (chrome-devtools://devtools....) you can debug but source maps are not working:

screen shot 2016-09-01 at 4 41 53 pm

I tried adding project to workspace / adding source maps manually with no luck. Am I doing something wrong here? Is there an issue here?

yanivefraim avatar Sep 01 '16 13:09 yanivefraim

Yep, this is a known limitation and it's not something that we can actually fix at this time. The issue is that the chrome debugger needs to know how to fetch the original source but the inspector code has no way of providing it yet.

jasnell avatar Sep 01 '16 14:09 jasnell

@jasnell How so? The sourcemap in this example is inlined. Isn't the data from the sourcemap sufficient? Sourcemaps in the browser can show the original source without having access to the actual files.

matthewoates avatar Sep 19 '16 01:09 matthewoates

poke @jasnell

matthewoates avatar Sep 28 '16 07:09 matthewoates

Ping

knownasilya avatar Oct 13 '16 18:10 knownasilya

/cc @nodejs/v8-inspector

MylesBorins avatar Oct 13 '16 18:10 MylesBorins

Any solution here guys? @jasnell @matthewoates

samuelcastro avatar Oct 21 '16 19:10 samuelcastro

hmm... I thought I had responded to this earlier today. Perhaps it got lost somewhere and will show up on wikileaks someday... in any case, there's no solution at this time. Source maps are not supported when using the chrome inspector with node because there is no mechanism by which to locate and load those source maps. We would need some one to figure out how to make it work and open a PR.

jasnell avatar Oct 21 '16 20:10 jasnell

Source maps aren't supported at the current time because there's no mechanism for loading them. It's something that has been discussed from time to time but there's been no resolution yet

On Friday, October 21, 2016, Samuel Castro [email protected] wrote:

Any solution here guys? @jasnell https://github.com/jasnell @matthewoates https://github.com/matthewoates

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/nodejs/node/issues/8369#issuecomment-255444367, or mute the thread https://github.com/notifications/unsubscribe-auth/AAa2eeQkUcpdzhyIVLU8GVxoyQY7tk1vks5q2Q8vgaJpZM4JytlQ .

jasnell avatar Oct 25 '16 18:10 jasnell

@jasnell - can you give some technical background/pointers on what's going on here? I'll happily try to help out if I can get a bit of direction.

Isn't this just stock Chrome DevTools UI integrating with node's debugging protocol exposed via v8-inspector? Chrome's DevTools support sourcemap loading already for frontend work, and the context menu option to "Add Source Map" exists when you right-click on the code pane. It seems non-functional though.

Unfortunately, a ton of people are using Babel/Typescript transpilation for node, and lack of sourcemaps leaves --inspect functionality severely hampered.

@pavelfeldman indicated in a couple places that they should work: https://github.com/nodejs/node/pull/6792#issuecomment-230902562 https://github.com/nodejs/node/issues/6725#issuecomment-219608884

EricMCornelius avatar Nov 03 '16 16:11 EricMCornelius

I'm chipping in because I've been a bit confused by this, and see no reason it shouldn't work given what's presented in Chrome.

  • Node version: 7.0
  • Platform: Windows 10
  • Chrome version: 54 stable

I'm using babel-node in development which outputs inline source maps by default, I assume it's pretty much the same with babel-register. In my case I simply run something like babel-node --inspect src/server/index.js. In Chrome, in the sources panel, the path in the file tree and in the tab title point to the original source file, and it says it detects a source map, but I get displayed the transpiled version of the code (which I believe is served from memory with babel-node).

source_map_1

When I click "more" this is the message: source_map_2 but there are no other versions of the same file in the file tree or when I press Ctrl + P.

If Chrome can both detect an inline source map and knows the path to my source, shouldn't this be able to work?

Debugging seems to work pretty much fine otherwise, other than a bug with the console sometimes not working correctly.

As an aside: I know it's probably not comparable, but I recently gave VS Code a go using the new Node debugger (referred to as node2) which uses the v8 inspector protocol, and source maps work fine there for the same use case (after setting "sourceMaps": true in launch.json).

noinkling avatar Nov 11 '16 04:11 noinkling

+1

pentateu avatar Nov 13 '16 22:11 pentateu

If you guys are opening the inspect link in Chrome, then I think they won't work because a webpage has no way of accessing the disk, right? Typically chrome devtools is run in a host that provides access to the disk and other things. Probably would work from the chrome://inspect page though.

roblourens avatar Nov 15 '16 16:11 roblourens

@robertchiras see my first comment. You don't need to access the filesystem for source maps to work.

matthewoates avatar Nov 15 '16 18:11 matthewoates

IIRC the problem is that Devtools wants to resolve all URLs (including data:) relative / in the context of the debug target's origin, not the origin of the Devtools page. This requires active support on the side of the debug target, tied into the network stack (which is not part of V8 and thus not (yet) instrumented in node). Obviously that doesn't make as much sense when debugging a server-side app locally. It becomes more important when debugging remotely or when origin policies come into play.

So my best guess is that the place to fix it would be the devtools frontend, potentially adding a special case there for data urls..?

hybrist avatar Nov 17 '16 15:11 hybrist

Possible duplicate on the devtools side: https://bugs.chromium.org/p/chromium/issues/detail?id=664801&q=component%3APlatform%3EDevTools%20node&colspec=ID%20Owner%20Summary%20Modified%20Stars

hybrist avatar Nov 17 '16 15:11 hybrist

This appears to be fixed in Node 7.2.1 and Canary. Can anyone else confirm?

joshunger avatar Dec 20 '16 01:12 joshunger

@joshunger Node 7.2.1 and Canary did not resolve the issue for me.

A workaround is to host the source map file...

Example: Run python -m SimpleHTTPServer, Then manually add //# sourceMappingURL=http://localhost:8000/main.js.map to the bottom of your source file.

zfedoran avatar Dec 20 '16 04:12 zfedoran

@joshunger This is working for me now with Node 7.2.1 & Canary (Version 57.0.2962.0 (Official Build) canary (64-bit) )

RanjithNair avatar Dec 25 '16 20:12 RanjithNair

Confirmed :smile: It's working here with Node 7.3.0 and Canay Version 57.0.2963.0

miksansegundo avatar Dec 27 '16 04:12 miksansegundo

I may have been on an older version of Canary when I tried this earlier. I can confirm that this does work for me as well with Version 57.0.2967.0 (Official Build) canary (64-bit) and Node 7.3.0.

zfedoran avatar Dec 30 '16 16:12 zfedoran