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.

Absolute URLs as sourceRoot not supported

See original GitHub issue

Bug report

When using an absolute URL as the sourceRoot, an error is thrown. According to multiple sources I found online, e.g. the typescript documentation, the sourceRoot field is allowed to be a path or an URL.

Actual Behavior

Using a sourceRoot like https://raw.githubusercontent.com/fb55/htmlparser2/4763205746cd80120b5d2b69041197a394d24ba9/src/ results in an error like this:

Failed to parse source map from 'C:\my-app\node_modules\htmlparser2\lib\esm\https:\raw.githubusercontent.com\fb55\htmlparser2\4763205746cd80120b5d2b69041197a394d24ba9\src\index.ts' file: Error: ENOENT: no such file or directory, open 'C:\my-app\node_modules\htmlparser2\lib\esm\https:\raw.githubusercontent.com\fb55\htmlparser2\4763205746cd80120b5d2b69041197a394d24ba9\src\index.ts'

As you can see, the absolute URL is threated as a relative path and joined with the context, resulting in an invalid URL/path.

Expected Behavior

The absolute URL in the sourceRoot should be combined with the “source” to result in the valid URL, and not prefixed with the context path: https://raw.githubusercontent.com/fb55/htmlparser2/4763205746cd80120b5d2b69041197a394d24ba9/src/index.ts

How Do We Reproduce?

The problem can easily be reproduced by adding the package htmlparser2@8.0.1 to a newly created create-react-app project and importing the package in the code. When running the react-scripts build command, the multiple warnings as seen above will be printed to the console.

An example source map for the htmlparser2 package looks like this:

{
    "version": 3,
    "file": "index.js",
    "sourceRoot": "https://raw.githubusercontent.com/fb55/htmlparser2/4763205746cd80120b5d2b69041197a394d24ba9/src/",
    "sources": ["index.ts"],
    "names": [],
    "mappings": "<truncated>"
}

These are the steps to reproduce the issue:

> yarn create react-app my-app
> cd my-app
> yarn add htmlparser2@8.0.1
# now add an import statement to the App.js: import * as htmlparser2 from "htmlparser2";
> yarn build

Please paste the results of npx webpack-cli info here, and mention other relevant information

  System:
    OS: Windows 10 10.0.19044
    CPU: (4) x64 Intel(R) Core(TM) i5-7600K CPU @ 3.80GHz
    Memory: 8.43 GB / 15.97 GB
  Binaries:
    Node: 16.13.2 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.15 - C:\Program Files\nodejs\yarn.CMD
    npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    <not relevant>

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rgischkcommented, Oct 21, 2022

@alexander-akait I managed to do it now. Sorry for the trouble and thank you for the quick responses.

1reaction
rgischkcommented, Oct 20, 2022

@alexander-akait the link is located in the “Contributor License Agreement” section and links to https://cla.js.foundation/webpack-contrib/source-map-loader. When I open it, I get the following message:

Error
There is no CLA to sign for webpack-contrib/source-map-loader

({"message":"Must specify access token via Authorization header. https://developer.github.com/changes/2020-02-10-deprecating-auth-through-query-param","documentation_url":"https://docs.github.com/v3/#oauth2-token-sent-in-a-header"})

Also I still don’t have any permissions to push a branch, so I cannot create a pull request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

mapRoot/sourceRoot write sourcemaps using absolute local ...
This stuff is not clearly spec'd but my understanding is that sourceMappingURL and sourceRoot should be URIs or relative paths, not local ...
Read more >
Angular 10 won't recognize absolute path aliases
Trying to get absolute pathing and aliases to work in my app. I keep getting errors. tsconfig.json: "compilerOptions": { "baseUrl": ".
Read more >
RFC-0119: System-absolute paths considered harmful - Fuchsia
Source code that is checked in can't reference absolute paths because they are not portable - they won't make sense on the Commit...
Read more >
Get Absolute Relative Path of File in IDEA IntelliJ - Code2care
Step 3: Select Absolute Path, File Name, Path from Content Root or Path from Source root options. Step 4: The text will get...
Read more >
Relative and absolute paths, in the file system and on the web ...
In the address like http://example.com/file.html , file.html is not a file. ... So again: an absolute path is one starting from the system...
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