Skip to content

Commit 7062449

Browse files
authored
fix(node): Only require inspector when needed (#9149)
1 parent 5f6ddb4 commit 7062449

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/node/src/anr/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Event, StackFrame } from '@sentry/types';
22
import { logger } from '@sentry/utils';
33
import { spawn } from 'child_process';
4-
import * as inspector from 'inspector';
54

65
import { addGlobalEventProcessor, captureEvent, flush } from '..';
76
import { captureStackTrace } from './debugger';
@@ -98,12 +97,19 @@ function sendEvent(blockedMs: number, frames?: StackFrame[]): void {
9897
});
9998
}
10099

100+
interface InspectorApi {
101+
open: (port: number) => void;
102+
url: () => string | undefined;
103+
}
104+
101105
/**
102106
* Starts the node debugger and returns the inspector url.
103107
*
104108
* When inspector.url() returns undefined, it means the port is already in use so we try the next port.
105109
*/
106110
function startInspector(startPort: number = 9229): string | undefined {
111+
// eslint-disable-next-line @typescript-eslint/no-var-requires
112+
const inspector: InspectorApi = require('inspector');
107113
let inspectorUrl: string | undefined = undefined;
108114
let port = startPort;
109115

0 commit comments

Comments
 (0)