Skip to content

Commit 9a57643

Browse files
committed
fix detection
1 parent 9ee96ab commit 9a57643

File tree

1 file changed

+15
-25
lines changed

1 file changed

+15
-25
lines changed
Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as moduleModule from 'node:module';
21
import { consoleSandbox } from '@sentry/core';
32

43
/** Detect CommonJS. */
@@ -10,40 +9,31 @@ export function isCjs(): boolean {
109
}
1110
}
1211

13-
/**
14-
* Check if the current Node.js version supports module.register
15-
*/
16-
export function supportsEsmLoaderHooks(): boolean {
17-
logIfUnsupportedNodeVersion();
18-
19-
return 'register' in moduleModule;
20-
}
21-
2212
let hasWarnedAboutNodeVersion: boolean | undefined;
2313

2414
/**
25-
* Log a warning if the current Node.js version is not supported in ESM mode
15+
* Check if the current Node.js version supports module.register
2616
*/
27-
function logIfUnsupportedNodeVersion(): void {
28-
if (hasWarnedAboutNodeVersion) {
29-
return;
30-
}
31-
17+
export function supportsEsmLoaderHooks(): boolean {
3218
if (isCjs()) {
33-
return;
19+
return false;
3420
}
3521

3622
const [nodeMajor = 0, nodeMinor = 0] = process.versions.node.split('.').map(Number);
3723
if (nodeMajor >= 21 || (nodeMajor === 20 && nodeMinor >= 6) || (nodeMajor === 18 && nodeMinor >= 19)) {
38-
return;
24+
return true;
3925
}
4026

41-
hasWarnedAboutNodeVersion = true;
27+
if (!hasWarnedAboutNodeVersion) {
28+
hasWarnedAboutNodeVersion = true;
29+
30+
consoleSandbox(() => {
31+
// eslint-disable-next-line no-console
32+
console.warn(
33+
`[Sentry] You are using Node.js v${process.versions.node} in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.`,
34+
);
35+
});
36+
}
4237

43-
consoleSandbox(() => {
44-
// eslint-disable-next-line no-console
45-
console.warn(
46-
`[Sentry] You are using Node.js v${process.versions.node} in ESM mode ("import syntax"). The Sentry Node.js SDK is not compatible with ESM in Node.js versions before 18.19.0 or before 20.6.0. Please either build your application with CommonJS ("require() syntax"), or upgrade your Node.js version.`,
47-
);
48-
});
38+
return false;
4939
}

0 commit comments

Comments
 (0)