Skip to content
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

Cannot resolve HTTP sourcemaps in Node #8

Open
nolanlawson opened this issue Dec 27, 2021 · 0 comments
Open

Cannot resolve HTTP sourcemaps in Node #8

nolanlawson opened this issue Dec 27, 2021 · 0 comments

Comments

@nolanlawson
Copy link

Hi, I noticed that I seem to be unable to resolve sourcemaps in Node. Here is a full repro with repro steps.

Notice that, in my repro web app, Chrome is able to parse the stacktrace for script.min.js (source: script.js), so the sourcemap seems to be configured correctly:

Screenshot from 2021-12-26 20-59-24

Yet, in Node.js, when I run:

const stacktrace = "Error\n    at http://localhost:3000/script.min.js:1:29"
console.log(new Stacktracey(stacktrace).withSources().asTable())

The output is:

at   script.min.js:1

Note that it says script.min.js, not script.js.

I believe I've tracked it down to these lines of code:

resolve (nodeRequire ('fs').readFileSync (path, { encoding: 'utf8' }))

nodeRequire ('fs').readFile (path, { encoding: 'utf8' }, (e, x) => {

Note that, in the browser version of the code, it does an XHR to fetch the path – i.e. it assumes it's a URL, not a filepath. But in Node, it assumes it's a filepath. So we get a "no such file or directory" error:

Screenshot from 2021-12-26 21-03-01

It seems to me that the Node code should be making an HTTP request rather than doing fs.readFile / fs.readFileSync, similar to what it does in the browser.

@nolanlawson nolanlawson changed the title Cannot resolve sourcemaps in Node Cannot resolve HTTP sourcemaps in Node Dec 27, 2021
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

No branches or pull requests

1 participant