Skip to content

Commit 1a10da7

Browse files
fix: source maps in Node v21.6.0+ & v20.12.0+ (#518)
Co-authored-by: Hiroki Osame <[email protected]>
1 parent 61b1836 commit 1a10da7

File tree

3 files changed

+17
-20
lines changed

3 files changed

+17
-20
lines changed

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20.10.0
1+
v20.12.0

src/source-map.ts

+13-17
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@ import type { Transformed } from './utils/transform/apply-transformers.js';
33
const inlineSourceMapPrefix = '\n//# sourceMappingURL=data:application/json;base64,';
44

55
export const installSourceMapSupport = () => {
6-
const hasNativeSourceMapSupport = (
7-
8-
/**
9-
* Check if native source maps are supported by seeing if the API is available
10-
* https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processsetsourcemapsenabledval
11-
*/
12-
'setSourceMapsEnabled' in process
13-
14-
/**
15-
* Overriding Error.prepareStackTrace prevents --enable-source-maps from modifying
16-
* the stack trace
17-
* https://nodejs.org/dist/latest-v18.x/docs/api/cli.html#:~:text=Overriding%20Error.prepareStackTrace%20prevents%20%2D%2Denable%2Dsource%2Dmaps%20from%20modifying%20the%20stack%20trace.
18-
*
19-
* https://github.com/nodejs/node/blob/91193825551f9301b6ab52d96211b38889149892/lib/internal/errors.js#L141
20-
*/
21-
&& typeof Error.prepareStackTrace !== 'function'
22-
);
6+
/**
7+
* Check if native source maps are supported by seeing if the API is available
8+
* https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processsetsourcemapsenabledval
9+
*
10+
* Previously, we also checked Error.prepareStackTrace to opt-out of source maps
11+
* as per this recommendation:
12+
* https://nodejs.org/dist/latest-v18.x/docs/api/cli.html#:~:text=Overriding%20Error.prepareStackTrace%20prevents%20%2D%2Denable%2Dsource%2Dmaps%20from%20modifying%20the%20stack%20trace.
13+
*
14+
* But it's been removed because:
15+
* 1. It's set by default from Node v21.6.0 and v20.12.0
16+
* 2. It may have been possible for a custom prepareStackTrace to parse the source maps
17+
*/
18+
const hasNativeSourceMapSupport = 'setSourceMapsEnabled' in process;
2319

2420
if (hasNativeSourceMapSupport) {
2521
process.setSourceMapsEnabled(true);

tests/utils/node-versions.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ export const nodeVersions = [
1313
&& process.platform !== 'win32'
1414
)
1515
? [
16-
'21.5.0',
17-
latestMajor('20.10.0'),
16+
latestMajor('21.7.2'),
17+
'21.0.0',
18+
latestMajor('20.12.0'),
1819
'20.0.0',
1920
latestMajor('18.20.0'),
2021
'18.0.0',

0 commit comments

Comments
 (0)