node
node copied to clipboard
Support remote sourceMap
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
similar https://issues.chromium.org/issues/40060207
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.
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.