Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,9 @@ is permitted.
<!-- YAML
added: v12.12.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/67627
description: Source maps in `node_modules` are skipped by default.
- version:
- v15.11.0
- v14.18.0
Expand All @@ -1287,6 +1290,9 @@ application reference the transpiled code, not the original source position.
`--enable-source-maps` enables caching of Source Maps and makes a best
effort to report stack traces relative to the original source file.

Source maps of files in `node_modules` are skipped. Use
[`module.setSourceMapsSupport()`][] to enable source maps for them.

Overriding `Error.prepareStackTrace` may prevent `--enable-source-maps` from
modifying the stack trace. Call and return the results of the original
`Error.prepareStackTrace` in the overriding function to modify the stack trace
Expand Down Expand Up @@ -5005,6 +5011,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
[`dnsPromises.lookup()`]: dns.md#dnspromiseslookuphostname-options
[`import.meta.url`]: esm.md#importmetaurl
[`inspector.open()`]: inspector.md#inspectoropenport-host-wait
[`module.setSourceMapsSupport()`]: module.md#modulesetsourcemapssupportenabled-options
[`net.getDefaultAutoSelectFamilyAttemptTimeout()`]: net.md#netgetdefaultautoselectfamilyattempttimeout
[`node:ffi`]: ffi.md
[`node:sqlite`]: sqlite.md
Expand Down
2 changes: 1 addition & 1 deletion doc/api/module.md
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,7 @@ This function enables or disables the [Source Map v3][Source Map] support for
stack traces.

It provides same features as launching Node.js process with commandline options
`--enable-source-maps`, with additional options to alter the support for files
`--enable-source-maps`, with additional options to enable the support for files
in `node_modules` or generated codes.

Only source maps in JavaScript files that are loaded after source maps has been
Expand Down
2 changes: 2 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,8 @@ When using a transpiler, such as TypeScript, stack traces thrown by an
application reference the transpiled code, not the original source position.
\fB--enable-source-maps\fR enables caching of Source Maps and makes a best
effort to report stack traces relative to the original source file.
Source maps of files in \fBnode_modules\fR are skipped. Use
\fBmodule.setSourceMapsSupport()\fR to enable source maps for them.
Overriding \fBError.prepareStackTrace\fR may prevent \fB--enable-source-maps\fR from
modifying the stack trace. Call and return the results of the original
\fBError.prepareStackTrace\fR in the overriding function to modify the stack trace
Expand Down
5 changes: 1 addition & 4 deletions lib/internal/process/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -804,12 +804,9 @@ function initializeSourceMapsHandlers() {
setSourceMapsSupport,
} = require('internal/source_map/source_map_cache');
const enabled = getOptionValue('--enable-source-maps');
// Source maps in node_modules are skipped by default.
setSourceMapsSupport(enabled, {
__proto__: null,
// TODO(legendecas): In order to smoothly improve the source map support,
// skip source maps in node_modules and generated code with
// `--enable-source-maps` in a semver major version.
nodeModules: enabled,
generatedCode: enabled,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Error.stackTraceLimit = 5;
assert.deepStrictEqual(Module.getSourceMapsSupport(), {
__proto__: null,
enabled: true,
nodeModules: true,
nodeModules: false,
generatedCode: true,
});
Module.setSourceMapsSupport(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Flags: --enable-source-maps

'use strict';
require('../../../common');
const assert = require('node:assert');
const Module = require('node:module');
Error.stackTraceLimit = 2;

// --enable-source-maps skips source maps in node_modules.
assert.deepStrictEqual(Module.getSourceMapsSupport(), {
__proto__: null,
enabled: true,
nodeModules: false,
generatedCode: true,
});

try {
require('../node_modules/error-stack/enclosing-call-site-min.js').simpleErrorStack();
} catch (e) {
console.log(e);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Error: an error!
at functionD (<project-root>/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site-min.js:1:156)
at functionC (<project-root>/test/fixtures/source-map/node_modules/error-stack/enclosing-call-site-min.js:1:97)
1 change: 1 addition & 0 deletions test/parallel/test-node-output-sourcemaps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe('sourcemaps output', { concurrency: !process.env.TEST_PARALLEL }, () =>
{ name: 'source-map/output/source_map_assert_ok_no_source_map.cjs' },
{ name: 'source-map/output/source_map_disabled_by_api.js' },
{ name: 'source-map/output/source_map_disabled_by_process_api.js' },
{ name: 'source-map/output/source_map_enable_source_maps_defaults.js' },
{ name: 'source-map/output/source_map_enabled_by_api.js' },
{ name: 'source-map/output/source_map_enabled_by_api_node_modules.js' },
{ name: 'source-map/output/source_map_enabled_by_process_api.js' },
Expand Down
Loading