Skip to content

Absolute URLs as sourceRoot not supported #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rgischk opened this issue Oct 1, 2022 · 8 comments · Fixed by #188
Closed

Absolute URLs as sourceRoot not supported #186

rgischk opened this issue Oct 1, 2022 · 8 comments · Fixed by #188

Comments

@rgischk
Copy link

rgischk commented Oct 1, 2022

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 [email protected] 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 [email protected]
# 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>
@alexander-akait
Copy link
Member

alexander-akait commented Oct 7, 2022

Fixed #188, anyway we don't support fetching remote URLs, so now we just fix sources as you written above, if you need it please write me here and I will look how we can implement this

@rgischk
Copy link
Author

rgischk commented Oct 17, 2022

@alexander-akait thank you for the quick fix. It works for me. But is there any chance we get this fix in a 3.0.2 release? We use create-react-app, and I don't see them migrate to the 4.x.x release any time soon, because they would have to increase their minimum supported Node.js version to 14.15.0.

@alexander-akait
Copy link
Member

I strongly recommend to update to v4, anyway I can accept the same fix (and PR) for v3 branch, feel free to send a PR

@rgischk
Copy link
Author

rgischk commented Oct 19, 2022

I created a branch from the 3.0.1 tag and cherry-picked your changes, but I do not have the permissions to push that branch. Also you said to create a PR, but what would be the target of that PR? There is no release branch for the 3.x.x line, is there? And finally the link to the CLA in your CONTRIBUTING.md seems to be broken, I get an error when I open it.

@alexander-akait
Copy link
Member

@rgischk Sorry for this, missed that branch doesn't exits, crated https://github.com/webpack-contrib/source-map-loader/tree/v3

And finally the link to the CLA in your CONTRIBUTING.md seems to be broken, I get an error when I open it.

Can you provide a place there is it?

@rgischk
Copy link
Author

rgischk commented 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.

@alexander-akait
Copy link
Member

@rgischk Just fork repo, when ccheckout on v3 branch, then create a branch based in v3, commit and put to own fork, when you can push it here

@rgischk
Copy link
Author

rgischk commented Oct 21, 2022

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

agoose77 added a commit to agoose77/jupyterlab-myst that referenced this issue May 12, 2023
Addresses error with nth-check source-map parsing: webpack-contrib/source-map-loader#186
agoose77 added a commit to jupyter-book/jupyterlab-myst that referenced this issue May 12, 2023
Addresses error with nth-check source-map parsing: webpack-contrib/source-map-loader#186
agoose77 added a commit to jupyter-book/jupyterlab-myst that referenced this issue May 15, 2023
* chore: simplify dependencies

* fix: update source-map-loader

Addresses error with nth-check source-map parsing: webpack-contrib/source-map-loader#186

* chore: upgrade to PyPI version
agoose77 added a commit to jupyter-book/jupyterlab-myst that referenced this issue May 30, 2023
* chore: simplify dependencies

* fix: update source-map-loader

Addresses error with nth-check source-map parsing: webpack-contrib/source-map-loader#186

* chore: upgrade to PyPI version
agoose77 added a commit to jupyter-book/jupyterlab-myst that referenced this issue Jun 11, 2023
* chore: simplify dependencies

* fix: update source-map-loader

Addresses error with nth-check source-map parsing: webpack-contrib/source-map-loader#186

* chore: upgrade to PyPI version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants