diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 14aa8d5d3203b9..17ccb009f7423d 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -309,19 +309,6 @@ function startup() { // others like the debugger or running --eval arguments. Here we decide // which mode we run in. function startExecution() { - // This means we are in a Worker context, and any script execution - // will be directed by the worker module. - if (!isMainThread) { - const workerThreadSetup = NativeModule.require( - 'internal/process/worker_thread_only' - ); - // Set up the message port and start listening - const { workerFatalExeception } = workerThreadSetup.setup(); - // Overwrite fatalException - process._fatalException = workerFatalExeception; - return; - } - // To allow people to extend Node in different ways, this hook allows // one to drop a file lib/_third_party_main.js into the build // directory which will be executed instead of Node's normal loading. @@ -392,6 +379,19 @@ function prepareUserCodeExecution() { } function executeUserCode() { + // If we are in a worker thread, execute the script sent through the + // message port. + if (!isMainThread) { + const workerThreadSetup = NativeModule.require( + 'internal/process/worker_thread_only' + ); + // Set up the message port and start listening + const { workerFatalExeception } = workerThreadSetup.setup(); + // Overwrite fatalException + process._fatalException = workerFatalExeception; + return; + } + // User passed `-e` or `--eval` arguments to Node without `-i` or // `--interactive`. // Note that the name `forceRepl` is merely an alias of `interactive`