question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

js-debug should follow redirects when requesting sourcemaps

See original GitHub issue

In my setup, the vscode debugger extension can’t load the source map for the browser app bundle anymore, even though it always used to work in previous versions of vscode. The error message given is Could not read source map for http://127.0.0.1:8080/App.d4a65e86.js: Unexpected end of JSON input.

Trace log is attached: vscode-debugadapter-1.json.gz

launch.json entry (probably not related, though) – chrome-helper.sh just launches a specific version of Chromium with a set of debugging extensions installed, so that we can share the setup more easily across the team. The path override is just necessary to map the files in the source map to local files, but it’s most definitely unrelated to this issue.

{
      "name": "Debug in Chromium",
      "type": "chrome",
      "request": "launch",
      "url": "http://127.0.0.1:8080/",
      "runtimeExecutable": "${workspaceRoot}/.vscode/chrome-helper.sh",
      "webRoot": "${workspaceRoot}/src",
      "smartStep": true,
      "sourceMaps": true,
      "sourceMapPathOverrides": {
        "../*": "${webRoot}/*"
      }
    }

VS Code Version: 1.47.1 on macOS 10.15.4

Additional info: The source map itself is fine, valid JSON, and works in the browser itself, and it used to work well in older versions of vscode, too. The error message given is Could not read source map for http://127.0.0.1:8080/App.d4a65e86.js: Unexpected end of JSON input.

I suspect it is because the source map URL is a redirect to the actual URL, which the new debugger can’t seem to deal with. Here’s the output of curl when you request the source map, as the debugger sees it.

As you can see, it requests source map at /, but gets redirected to /app. This should, however, be allowed, I think, and works fine with browsers and older versions of the debugger, so I have a strong suspicion that maybe the redirect is what causes the confusion, and the “Unexpected end of JSON input” error is bogus, because the redirect response does not contain a body.

Unfortunately, I can’t share the source map itself (since the app is not open-source), but please take my word that the source map itself is perfectly valid 😃

gck@tenenbaum$ curl -Ivvv 'http://127.0.0.1:8080/App.d4a65e86.js.map'
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> HEAD /App.d4a65e86.js.map HTTP/1.1
> Host: 127.0.0.1:8080
> User-Agent: curl/7.64.1
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
HTTP/1.1 301 Moved Permanently
< content-length: 0
content-length: 0
< location: /app/App.d4a65e86.js.map
location: /app/App.d4a65e86.js.map
< connection: keep-alive
connection: keep-alive
< date: Wed, 22 Jul 2020 09:34:07 GMT
date: Wed, 22 Jul 2020 09:34:07 GMT

< 
* Connection #0 to host 127.0.0.1 left intact
* Closing connection 0

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
gkaindlcommented, Jul 28, 2020

Just a quick update: It turned out that there was a bug in SwiftNIO that would cause a part of the compressed response to be missing in a specific code path, and that would cause a non-stream-oriented decompressor to choke when decompressing it – which is what happened to got.

The issue has been resolved now, so I don’t think an option to load source maps with Accept-encoding: identity is needed anymore!

Thank you for your help in looking into this!

1reaction
gkaindlcommented, Jul 22, 2020

Thanks for putting it into the milestone! 😃

In the mean time, I’ve adapted the debug build of my backend to deliver the source map without a redirect, and I can confirm that this was/is the problem, so following redirects should fix it!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to force relative source map URL to follow redirect
I believe this is because the browser thinks that since the original requested URL is https://unpkg.com/numeric-quantity , then the ...
Read more >
Advanced Features: Debugging - Next.js
This documentation explains how you can debug your Next.js frontend and backend code with full source maps support using either the VS Code...
Read more >
JavaScript Debugging with Sourcemaps - TrackJS
The main purpose of sourcemaps is to aid debugging. Basically, if there's an error in the generated code file, the map can tell...
Read more >
SourceMap - HTTP - MDN Web Docs
The SourceMap HTTP response header links generated code to a source map, enabling the browser to reconstruct the original source and present ...
Read more >
4 Reasons Why Your Source Maps are Broken - Sentry Blog
This value must be a valid URI. If it is a relative URL, it is relative to the path location of the bundled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found