Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: do not use process.exit() #25769

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,12 @@ module.exports = Module;
let asyncESM;
let ModuleJob;
let createDynamicModule;
let decorateErrorStack;

function lazyLoadESM() {
asyncESM = require('internal/process/esm_loader');
ModuleJob = require('internal/modules/esm/module_job');
createDynamicModule = require(
'internal/modules/esm/create_dynamic_module');
decorateErrorStack = require('internal/util').decorateErrorStack;
}

const {
Expand Down Expand Up @@ -794,9 +792,7 @@ Module.runMain = function() {
return loader.import(pathToFileURL(process.argv[1]).pathname);
})
.catch((e) => {
decorateErrorStack(e);
console.error(e);
process.exit(1);
internalBinding('util').triggerFatalException(e);
});
} else {
Module._load(process.argv[1], null, true);
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/modules/esm/module_job.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const { decorateErrorStack } = require('internal/util');
const assert = require('assert');
const resolvedPromise = SafePromise.resolve();

function noop() {}

/* A ModuleJob tracks the loading of a single Module, and the ModuleJobs of
* its dependencies, over time. */
class ModuleJob {
Expand Down Expand Up @@ -41,6 +43,9 @@ class ModuleJob {
};
// Promise for the list of all dependencyJobs.
this.linked = link();
// This promise is awaited later anyway, so silence
// 'unhandled rejection' warnings.
this.linked.catch(noop);

// instantiated == deep dependency jobs wrappers instantiated,
// module wrapper instantiated
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-worker-esm-missing-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const { Worker } = require('worker_threads');

const worker = new Worker('./does-not-exist.js', {
execArgv: ['--experimental-modules'],
});

worker.on('error', common.mustCall((err) => {
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
assert(/Cannot find module .+does-not-exist.js/.test(err.message), err);
}));