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.

Support absolute file:// paths in sourceMappingURL

See original GitHub issue

Hi! I’m working on https://github.com/mozilla/tofino and we have some interesting requirements. It appears that we need absolute file:// paths in our sourceMappingURL to support source maps in the (Chrome) devtools that Electron provides natively. That is, we want:

//# sourceMappingURL=file:///Users/nalexander/Mozilla/tofino/lib/main/browser.map

Unfortunately, that conflicts with source-map-support, which doesn’t appreciate absolute paths of this kind. Would you merge a patch to handle (in Node.js only) file:// protocols?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

1reaction
nadakocommented, Jul 16, 2016

Same issue here with source maps generated by Haxe. Please fix 😃

1reaction
psulekcommented, Jun 16, 2016

I got same problems with electron and found maybe easy fix?

My webpacked bundled output js has this line on end: //# sourceMappingURL=appr.js.map which is relative path (just file name).

Problem seems to be in function:

function supportRelativeURL(file, url) {
  if (!file) return url;
  var dir = path.dirname(file);
  var match = /^\w+:\/\/[^\/]*/.exec(dir);
  var protocol = match ? match[0] : '';
  return protocol + path.resolve(dir.slice(protocol.length), url);
}

which incorrectly extract “protocol” information from file param when value is like file:///c:/dev/script1.js (local file protocol).

regex extract protocol value to file:// instead of file:/// (missing 3rd slash). It seems that problem is in this regex: var match = /^\w+:\/\/[^\/]*/.exec(dir);

And reason why param file has file:/// protocol: Electron loads html page in renderer process from file on disk, so function function wrapCallSite(frame) gets file:///c:/dev/script1.js on line: var source = frame.getFileName() || frame.getScriptNameOrSourceURL();

Possible fix will be to update regex on line var match = /^\w+:\/\/[^\/]*/.exec(dir); to correcly match http|s|file:/// protocols. Sorry i havent time now to do patch so if someone had time to do that it will be super.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Which is the base url of sourcemappingurl: relative from html ...
I lookup to the specification. When the source mapping URL is not absolute, then it is relative to the generated code's “source origin”....
Read more >
Relative vs absolute path for sourceMappingURL - #sentry
So my minified Javascript is located at: https://jobs.apploi.com/public/dist/index.min.js And in that file, on the last line, the following ...
Read more >
SourceMap - HTTP - MDN Web Docs
A relative (to the request URL) or absolute URL pointing to a source map file. Examples. SourceMap: /path/to/file.js.map
Read more >
SourceMapDevToolPlugin - webpack
Usually the #sourceMappingURL comment. [url] is replaced with a URL to the source map file. Since webpack v4.36.0, path parameters are supported: [chunk] ......
Read more >
source-map-support - npm
sourceMappingURL =path/to/source.map. If multiple sourceMappingURL comments exist in one file, the last sourceMappingURL comment will be ...
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