Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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: 5 additions & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,9 +794,13 @@ Module.runMain = function() {
return loader.import(pathToFileURL(process.argv[1]).pathname);
})
.catch((e) => {
// TODO(addaleax): This should, ideally, trigger a fatal exception
Comment thread
addaleax marked this conversation as resolved.
Outdated
// instead. That should alread be doable for code in core now, but it's
// probably easier to wait until something like
// https://github.com/nodejs/node/pull/25715 lands?
decorateErrorStack(e);
console.error(e);
process.exit(1);
process.exitCode = 1;
});
} 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
17 changes: 17 additions & 0 deletions test/parallel/test-worker-esm-missing-main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'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'],
stderr: true
});

let stderr = '';
worker.stderr.setEncoding('utf8');
worker.stderr.on('data', (chunk) => stderr += chunk);
worker.stderr.on('end', common.mustCall(() => {
// eslint-disable-next-line node-core/no-unescaped-regexp-dot
assert(/Cannot find module .+does-not-exist.js/.test(stderr), stderr);
}));