Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bd82adb

Browse filesBrowse files
targosMylesBorins
authored andcommitted
esm: exit the process with an error if loader has an issue
Previously, this would trigger an unhandled rejection that the user cannot handle. Fixes: #30205 PR-URL: #30219 Reviewed-By: Guy Bedford <guybedford@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
1 parent 7e1f050 commit bd82adb
Copy full SHA for bd82adb

File tree

Expand file treeCollapse file tree

5 files changed

+43
-10
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

5 files changed

+43
-10
lines changed
Open diff view settings
Collapse file

‎lib/internal/bootstrap/pre_execution.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/pre_execution.js
+10-10Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -480,16 +480,16 @@ function runMainESM(mainPath) {
480480
return esmLoader.initializeLoader().then(() => {
481481
const main = path.isAbsolute(mainPath) ?
482482
pathToFileURL(mainPath).href : mainPath;
483-
return esmLoader.ESMLoader.import(main).catch((e) => {
484-
if (hasUncaughtExceptionCaptureCallback()) {
485-
process._fatalException(e);
486-
return;
487-
}
488-
internalBinding('errors').triggerUncaughtException(
489-
e,
490-
true /* fromPromise */
491-
);
492-
});
483+
return esmLoader.ESMLoader.import(main);
484+
}).catch((e) => {
485+
if (hasUncaughtExceptionCaptureCallback()) {
486+
process._fatalException(e);
487+
return;
488+
}
489+
internalBinding('errors').triggerUncaughtException(
490+
e,
491+
true /* fromPromise */
492+
);
493493
});
494494
}
495495

Collapse file
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Flags: --experimental-modules --experimental-loader i-dont-exist
2+
import '../common/index.mjs';
3+
console.log('This should not be printed');
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
(node:*) ExperimentalWarning: The ESM module loader is experimental.
2+
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
3+
internal/modules/esm/default_resolve.js:*
4+
let url = moduleWrapResolve(specifier, parentURL);
5+
^
6+
7+
Error: Cannot find package 'i-dont-exist' imported from *
8+
at Loader.resolve [as _resolve] (internal/modules/esm/default_resolve.js:*:*)
9+
at Loader.resolve (internal/modules/esm/loader.js:*:*)
10+
at Loader.getModuleJob (internal/modules/esm/loader.js:*:*)
11+
at Loader.import (internal/modules/esm/loader.js:*:*)
12+
at internal/process/esm_loader.js:*:*
13+
at Object.initializeLoader (internal/process/esm_loader.js:*:*)
14+
at runMainESM (internal/bootstrap/pre_execution.js:*:*)
15+
at Function.Module.runMain (internal/modules/cjs/loader.js:*:*)
16+
at internal/main/run_main_module.js:*:* {
17+
code: 'ERR_MODULE_NOT_FOUND'
18+
}
Collapse file
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Flags: --experimental-modules --experimental-loader ./test/fixtures/es-module-loaders/syntax-error.mjs
2+
import '../common/index.mjs';
3+
console.log('This should not be printed');
Collapse file
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
(node:*) ExperimentalWarning: The ESM module loader is experimental.
2+
(node:*) ExperimentalWarning: --experimental-loader is an experimental feature. This feature could change at any time
3+
file://*/test/fixtures/es-module-loaders/syntax-error.mjs:2
4+
await async () => 0;
5+
^^^^^
6+
7+
SyntaxError: Unexpected reserved word
8+
at Loader.moduleStrategy (internal/modules/esm/translators.js:*:*)
9+
at async link (internal/modules/esm/module_job.js:*:*)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.