Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

vscode has issues with Inline Souremap Encoding #120

Closed
t83714 opened this issue Oct 9, 2017 · 8 comments
Closed

vscode has issues with Inline Souremap Encoding #120

t83714 opened this issue Oct 9, 2017 · 8 comments
Labels

Comments

@t83714
Copy link

t83714 commented Oct 9, 2017

Currently, the inline sourcemap generated by @std/esm is not in base64 encoding.
Here is one example:

data:application/json;charset=utf-8,%7B%22version%22:3,%22sources%22:%5B%22/Users/user/Development/node_modules/xyz/index.js%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA%22%7D

It seems vscode & chrome inpsector debugger will always assume a data URI for the inline sourcemap is in base64 encoding (even if the ;base64 extension is not included in the data URI scheme).

This will lead to data decoding error. e.g. vscode will report error similart to this:

SourceMaps.getMapForGeneratedPath: exception while processing path: /Users/user/Development/node_modules/toyrobotsimulator/index.js, sourcemap: data:application/json;charset=utf-8,%7B%22version%22:3,%22sources%22:%5B%22/Users/user/Development/node_modules/xyz/index.js%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA%22%7D
SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)

Could we please change the inline sourcemap encoding to base64?

@jdalton
Copy link
Member

jdalton commented Oct 9, 2017

@t83714

Sure I can! Worth noting I haven't seen the issue using Chrome 61 or with whatever version of inspector Electron uses.

Are you testing with node --inspect? Or uses the inspector within vscode only?

Can you file a bug on vscode too with the version number you've used and steps to perform a simple repro?

@t83714
Copy link
Author

t83714 commented Oct 10, 2017

Testing with vscode (Version 1.17.0) with node --inspect-brk=43701 -r @std/esm index.js and got the following error:

Debugging with inspector protocol because Node.js v8.6.0 was detected.
node --inspect-brk=43701 -r @std/esm index.js 
Debugger listening on ws://127.0.0.1:43701/47554922-5c90-482e-9126-9a7c3bf70bdf
Debugger attached.
SourceMaps.getMapForGeneratedPath: exception while processing path: /Users/user/Development/xyz/index.js, sourcemap: data:application/json;charset=utf-8,%7B%22version%22:3,%22sources%22:%5B%22/Users/user/Development/xyz/index.js%22%5D,%22names%22:%5B%5D,%22mappings%22:%22AAAA;AACA;AACA;AACA;AACA;AACA%22%7D
SyntaxError: Unexpected token � in JSON at position 0
    at JSON.parse (<anonymous>)
    at new SourceMap (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/vscode-chrome-debug-core/out/src/sourceMaps/sourceMap.js:20:25)
    at sourceMapContentsP.then.contents (/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/ms-vscode.node-debug2/node_modules/vscode-chrome-debug-core/out/src/sourceMaps/sourceMapFactory.js:53:28)

Had another try. It works on lastest Chrome (Version 61.0.3163.100) now.
Could be the outdated version that caused the issue. Sorry for the confusion.

Have filed a bug on vscode for this issue 35978

Thanks!

@jdalton
Copy link
Member

jdalton commented Oct 10, 2017

Thanks!

I'll defer to the vscode bug.

Update:

Root caused to convert-source-map dep; thlorenz/convert-source-map#59.

@jdalton jdalton closed this as completed Oct 10, 2017
@jdalton jdalton changed the title Both vscode & Chrome Inspect debugger have issues with Inline Souremap Encoding vscode has issues with Inline Souremap Encoding Oct 10, 2017
@t83714
Copy link
Author

t83714 commented Oct 10, 2017

Any chance for the future version of @std/esm to use base64 encoded data URI.
The current encoding is correct & valid data URI scheme.
However, many data URI decoder implementation assumes base64 encoding by default incorrectly --- tried a few online decoder and it seems many of them didn't work properly.
Change it to base64 will make it less chance it to break --- even it's the issue of other libs.

@jdalton
Copy link
Member

jdalton commented Oct 10, 2017

My main concern is node --inspect and Chromium based inspecting (through Electron). Since those cases are covered I rather avoid the overhead of base64 encoding if possible since the source mapping is just a nice-to-have way to avoid seeing the instrumented code behind the scenes.

I'm OK with punting this to vscode or its dependencies.

@t83714
Copy link
Author

t83714 commented Oct 11, 2017

No problem. Thanks for the note.

@Pokute
Copy link

Pokute commented Jul 19, 2018

This bug still happens and it is as you've thought, @jdalton. VSCode's node debugger expects that source maps are formatted in base64. I've managed to hack it to work, but it'll take a while until I can do a PR for ms-vscode.node-debug.

@jdalton
Copy link
Member

jdalton commented Jul 19, 2018

Hi @Pokute!

I'm following along on the VSCode side and have volunteered to do a PR too. If you beat me to it that's great as well. I imagine it's just a few lines. I've outlined the function to modify in the issue thread. See microsoft/vscode#35978 (comment).

Update:

Thanks @Pokute for patching it! It should land in tomorrow's Insiders build.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants