Absolute URLs as sourceRoot not supported
See original GitHub issueBug 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:
- Created a year ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
@alexander-akait I managed to do it now. Sorry for the trouble and thank you for the quick responses.
@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:Also I still don’t have any permissions to push a branch, so I cannot create a pull request.