Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: source maps in Node v21.6.0+ & v20.12.0+ #518

Merged
merged 13 commits into from
Apr 4, 2024
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.10.0
v20.12.0
30 changes: 13 additions & 17 deletions src/source-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,19 @@ import type { Transformed } from './utils/transform/apply-transformers.js';
const inlineSourceMapPrefix = '\n//# sourceMappingURL=data:application/json;base64,';

export const installSourceMapSupport = () => {
const hasNativeSourceMapSupport = (

/**
* Check if native source maps are supported by seeing if the API is available
* https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processsetsourcemapsenabledval
*/
'setSourceMapsEnabled' in process

/**
* Overriding Error.prepareStackTrace prevents --enable-source-maps from modifying
* the stack trace
* 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.
*
* https://github.com/nodejs/node/blob/91193825551f9301b6ab52d96211b38889149892/lib/internal/errors.js#L141
*/
&& typeof Error.prepareStackTrace !== 'function'
);
/**
* Check if native source maps are supported by seeing if the API is available
* https://nodejs.org/dist/latest-v18.x/docs/api/process.html#processsetsourcemapsenabledval
*
* Previously, we also checked Error.prepareStackTrace to opt-out of source maps
* as per this recommendation:
* 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.
*
* But it's been removed because:
* 1. It's set by default from Node v21.6.0 and v20.12.0
* 2. It may have been possible for a custom prepareStackTrace to parse the source maps
*/
const hasNativeSourceMapSupport = 'setSourceMapsEnabled' in process;

if (hasNativeSourceMapSupport) {
process.setSourceMapsEnabled(true);
Expand Down
5 changes: 3 additions & 2 deletions tests/utils/node-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ export const nodeVersions = [
&& process.platform !== 'win32'
)
? [
'21.5.0',
latestMajor('20.10.0'),
latestMajor('21.7.2'),
'21.0.0',
latestMajor('20.12.0'),
'20.0.0',
latestMajor('18.20.0'),
'18.0.0',
Expand Down
Loading