diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index af31a2c1a23910..ac56ae3c00651b 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -115,12 +115,9 @@ if (isMainThread) { } const { - onWarning, emitWarning } = NativeModule.require('internal/process/warning'); -if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') { - process.on('warning', onWarning); -} + process.emitWarning = emitWarning; const { diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 7929cbf2460c08..19ca59fa0cf7ff 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -8,6 +8,8 @@ let traceEventsAsyncHook; function prepareMainThreadExecution() { setupTraceCategoryState(); + setupWarningHandler(); + // Only main thread receives signals. setupSignalHandlers(); @@ -36,6 +38,15 @@ function prepareMainThreadExecution() { loadPreloadModules(); } +function setupWarningHandler() { + const { + onWarning + } = require('internal/process/warning'); + if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') { + process.on('warning', onWarning); + } +} + function initializeReport() { if (!getOptionValue('--experimental-report')) { return; @@ -268,6 +279,7 @@ function loadPreloadModules() { } module.exports = { + setupWarningHandler, prepareMainThreadExecution, initializeDeprecations, initializeESMLoader, diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index 0dc1b61ef94f45..4ecceff4e6ec41 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -4,6 +4,7 @@ // message port. const { + setupWarningHandler, initializeDeprecations, initializeESMLoader, initializeFrozenIntrinsics, @@ -39,6 +40,8 @@ const { const publicWorker = require('worker_threads'); const debug = require('util').debuglog('worker'); +setupWarningHandler(); + debug(`[${threadId}] is setting up worker child environment`); // Set up the message port and start listening