Skip to content

Commit f335723

Browse files
committed
put try/catch inside our flag, to postpone for now having to deal with the exception handling for unflagged usage
1 parent 737e831 commit f335723

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

lib/internal/modules/run_main.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ function executeUserEntryPoint(main = process.argv[1]) {
164164
if (!useESMLoader) {
165165
// Module._load is the monkey-patchable CJS module loader.
166166
const { Module } = require('internal/modules/cjs/loader');
167-
try {
168-
Module._load(main, null, true);
169-
} catch (error) {
170-
if (getOptionValue('--experimental-detect-module')) {
167+
if (getOptionValue('--experimental-detect-module')) {
168+
try {
169+
Module._load(main, null, true);
170+
} catch (error) {
171171
const { cjsRetryAsESMCache } = require('internal/modules/cjs/loader');
172172
const source = cjsRetryAsESMCache.get(resolvedMain);
173173
cjsRetryAsESMCache.delete(resolvedMain);
@@ -176,11 +176,11 @@ function executeUserEntryPoint(main = process.argv[1]) {
176176
if (!retryAsESM) {
177177
const { enrichCJSError } = require('internal/modules/esm/translators');
178178
enrichCJSError(error, source, resolvedMain);
179+
throw error;
179180
}
180181
}
181-
if (!retryAsESM) {
182-
throw error;
183-
}
182+
} else {
183+
Module._load(main, null, true);
184184
}
185185
}
186186

0 commit comments

Comments
 (0)