Skip to content

Commit dddac2c

Browse files
authored
fix(node): import worker_threads and fix node v14 types (#10791)
Since v8 increases our minimum supported node version, we no longer need to conditionally `dynamicRequire` the `worker_threads` module.
1 parent 722183b commit dddac2c

File tree

1 file changed

+2
-18
lines changed
  • packages/node-experimental/src/integrations/anr

1 file changed

+2
-18
lines changed

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

+2-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { URL } from 'url';
22
import { defineIntegration, getCurrentScope } from '@sentry/core';
33
import type { Contexts, Event, EventHint, IntegrationFn } from '@sentry/types';
4-
import { dynamicRequire, logger } from '@sentry/utils';
5-
import type { Worker, WorkerOptions } from 'worker_threads';
4+
import { logger } from '@sentry/utils';
5+
import { Worker } from 'worker_threads';
66
import { NODE_MAJOR, NODE_VERSION } from '../../nodeVersion';
77
import type { NodeClient } from '../../sdk/client';
88
import type { AnrIntegrationOptions, WorkerStartData } from './common';
@@ -11,24 +11,10 @@ import { base64WorkerScript } from './worker-script';
1111
const DEFAULT_INTERVAL = 50;
1212
const DEFAULT_HANG_THRESHOLD = 5000;
1313

14-
type WorkerNodeV14 = Worker & { new (filename: string | URL, options?: WorkerOptions): Worker };
15-
16-
type WorkerThreads = {
17-
Worker: WorkerNodeV14;
18-
};
19-
2014
function log(message: string, ...args: unknown[]): void {
2115
logger.log(`[ANR] ${message}`, ...args);
2216
}
2317

24-
/**
25-
* We need to use dynamicRequire because worker_threads is not available in node < v12 and webpack error will when
26-
* targeting those versions
27-
*/
28-
function getWorkerThreads(): WorkerThreads {
29-
return dynamicRequire(module, 'worker_threads');
30-
}
31-
3218
/**
3319
* Gets contexts by calling all event processors. This relies on being called after all integrations are setup
3420
*/
@@ -112,8 +98,6 @@ async function _startWorker(client: NodeClient, _options: Partial<AnrIntegration
11298
}
11399
}
114100

115-
const { Worker } = getWorkerThreads();
116-
117101
const worker = new Worker(new URL(`data:application/javascript;base64,${base64WorkerScript}`), {
118102
workerData: options,
119103
});

0 commit comments

Comments
 (0)