nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.26k stars 29.44k forks source link

Support remote sourceMap #51781

Open Jack-Works opened 8 months ago

Jack-Works commented 8 months ago

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

himself65 commented 8 months ago

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

legendecas commented 8 months ago

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 commented 8 months ago

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.

github-actions[bot] commented 1 month ago

There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the https://github.com/nodejs/node/labels/never-stale label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document.

github-actions[bot] commented 4 weeks ago

There has been no activity on this feature request and it is being closed. If you feel closing this issue is not the right thing to do, please leave a comment.

For more information on how the project manages feature requests, please consult the feature request management document.