Skip to content

Commit

Permalink
Ensure using the nodejs source-map support
Browse files Browse the repository at this point in the history
When using libraries like js-dom that provide a browser-like api inside nodejs, the source map support can be tricked into thinking that it is running in a browsers, which will attempt to use `XMLHttpRequest` instead of `require('fs')`. Depending on implementation of the XMLHttpRequest (presumably loaded by js-dom or alternative), this can be much slower to load source maps from disk, causing a higher latency run of nodejs. 

Even if the user is using a browser-like experience within nodejs, the nodejs implementation of source map support should always be superior, thus we should hint to the source map support to always use the nodejs fs module to load source maps. 

For me, I noticed this slow down in test runs, and found an 80% speedup across some runs. Other's mileage may vary.
  • Loading branch information
joeljeske authored and alexeagle committed Feb 17, 2021
1 parent d82eb0e commit db98319
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/node/require_patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ module.constructor._resolveFilename =
try {
const sourcemap_support_package = path.resolve(
process.cwd(), '../build_bazel_rules_nodejs/third_party/github.com/source-map-support');
require(sourcemap_support_package).install();
require(sourcemap_support_package).install({ environment: 'node' });
} catch (_) {
log_verbose(`WARNING: source-map-support module not installed.
Stack traces from languages like TypeScript will point to generated .js files.`);
Expand Down

0 comments on commit db98319

Please sign in to comment.