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

Support remote sourceMap #51781

Open
Jack-Works opened this issue Feb 16, 2024 · 3 comments
Open

Support remote sourceMap #51781

Jack-Works opened this issue Feb 16, 2024 · 3 comments
Labels
feature request Issues that request new features to be added to Node.js. source maps Issues and PRs related to source map support.

Comments

@Jack-Works
Copy link

What is the problem this feature will solve?

In some size-sensitive cases, we want to compress the output to ship smaller packages, we also want to keep useful stack traces for bug reports. Therefore I hope Node.js can resolve remote sourceMap files.

What is the feature you are proposing to solve the problem?

Resolve sourceMap at a remote URL. Here is an example (that it does not work today):

// a.js
import { __addDisposableResource, __disposeResources } from "tslib";
throw new Error();
var x;
const env_1 = { stack: [], error: void 0, hasError: false };
try {
    x = __addDisposableResource(env_1, undefined, false);
}
catch (e_1) {
    env_1.error = e_1;
    env_1.hasError = true;
}
finally {
    __disposeResources(env_1);
}
//# sourceMappingURL=http://127.0.0.1:8080/a.js.map
// http://127.0.0.1:8080/a.js.map
{"version":3,"file":"a.js","sourceRoot":"","sources":["a.ts"],"names":[],"mappings":";AAAA,MAAM,IAAI,KAAK,EAAE,CAAA;;;;IACX,mCAAI,SAAS,QAAA,CAAA","sourcesContent":["throw new Error()\nusing x = undefined\nexport {}\n\n"]}

Run node --enable-source-maps ./a.js does not use the sourcemap.

What alternatives have you considered?

No response

@Jack-Works Jack-Works added the feature request Issues that request new features to be added to Node.js. label Feb 16, 2024
@himself65
Copy link
Member

@himself65 himself65 added the source maps Issues and PRs related to source map support. label Feb 17, 2024
@legendecas
Copy link
Member

I think this should be enabled with a separate flag or with custom loaders, e.g. some flags like --experimental-network-imports. This would allow network access through JavaScript comments (magic source map comments) and introduce differences in application stability and security concerns.

similar https://issues.chromium.org/issues/40060207

File URL as source mapping url is already supported at the moment. Additionally, the current security model defines that user scripts on the file system are trusted so I don't think this issue is related to the requested feature.

@legendecas
Copy link
Member

I think this can be integrated with the flag --experimental-network-imports because with that flag, the sources are generally loaded from the network and their source maps need to be loaded from the network as well.

Quick prototyping with a custom loader: https://github.com/legendecas/network-source-maps-loader. Ultimately, I think a new optional phase can be introduced to load source maps with V8 parsed source map magic comments to avoid regexp matching and string concatenation in the loaders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. source maps Issues and PRs related to source map support.
Projects
Status: Awaiting Triage
Development

No branches or pull requests

3 participants