Skip to content

Commit 056f944

Browse files
authored
feat(esm): Import rather than require inspector (#10910)
This does break support for custom builds of Node which have been built without inspector support. The only one that comes to mind is Vercel/pkg but this has recently been deprecated since Node v21 supports building single file executables. We may come back later and find a way to work around this but we cannot use async `import` with the current code, so we'll need to revisit this after we have a proper ESM build working! This also removes `local-variables-async.ts` since it's not used and async inspector requires a worker thread to work.
1 parent f655931 commit 056f944

File tree

5 files changed

+4
-3690
lines changed

5 files changed

+4
-3690
lines changed

packages/node-experimental/src/integrations/anr/index.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { defineIntegration, getCurrentScope } from '@sentry/core';
22
import type { Contexts, Event, EventHint, IntegrationFn } from '@sentry/types';
33
import { logger } from '@sentry/utils';
4+
import * as inspector from 'inspector';
45
import { Worker } from 'worker_threads';
56
import { NODE_MAJOR, NODE_VERSION } from '../../nodeVersion';
67
import type { NodeClient } from '../../sdk/client';
@@ -29,11 +30,6 @@ async function getContexts(client: NodeClient): Promise<Contexts> {
2930
return event?.contexts || {};
3031
}
3132

32-
interface InspectorApi {
33-
open: (port: number) => void;
34-
url: () => string | undefined;
35-
}
36-
3733
const INTEGRATION_NAME = 'Anr';
3834

3935
const _anrIntegration = ((options: Partial<AnrIntegrationOptions> = {}) => {
@@ -90,8 +86,6 @@ async function _startWorker(client: NodeClient, _options: Partial<AnrIntegration
9086
};
9187

9288
if (options.captureStackTrace) {
93-
// eslint-disable-next-line @typescript-eslint/no-var-requires
94-
const inspector: InspectorApi = require('inspector');
9589
if (!inspector.url()) {
9690
inspector.open(0);
9791
}

packages/node-experimental/src/integrations/anr/worker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { createGetModuleFromFilename } from '../../utils/module';
2121
import type { WorkerStartData } from './common';
2222

2323
type VoidFunction = () => void;
24-
type InspectorSessionNodeV12 = InspectorSession & { connectToMainThread: VoidFunction };
2524

2625
const options: WorkerStartData = workerData;
2726
let session: Session | undefined;
@@ -139,7 +138,7 @@ let debuggerPause: VoidFunction | undefined;
139138
if (options.captureStackTrace) {
140139
log('Connecting to debugger');
141140

142-
const session = new InspectorSession() as InspectorSessionNodeV12;
141+
const session = new InspectorSession();
143142
session.connectToMainThread();
144143

145144
log('Connected to debugger');

0 commit comments

Comments
 (0)