Skip to content

Commit c02af13

Browse files
authored
Attempt workaround for node regression (#1838)
* attempt workaround for node regression * lint-fix * fix
1 parent 11424e0 commit c02af13

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

dist-raw/runmain-hack.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const {pathToFileURL} = require('url');
2+
3+
// Hack to avoid Module.runMain on node 18.6.0
4+
// Keeping it simple for now, isolated in this file.
5+
// Could theoretically probe `getFormat` impl to determine if `import()` or `Module._load()` is best
6+
// Note that I attempted a try-catch around `Module._load`, but it poisons some sort of cache such that subsequent `import()` is impossible.
7+
exports.run = function(entryPointPath) {
8+
import(pathToFileURL(entryPointPath));
9+
}

src/bin.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,15 @@ function phase4(payload: BootstrapState) {
639639

640640
// Execute the main contents (either eval, script or piped).
641641
if (executeEntrypoint) {
642-
Module.runMain();
642+
if (
643+
payload.isInChildProcess &&
644+
versionGteLt(process.versions.node, '18.6.0')
645+
) {
646+
// HACK workaround node regression
647+
require('../dist-raw/runmain-hack.js').run(entryPointPath);
648+
} else {
649+
Module.runMain();
650+
}
643651
} else {
644652
// Note: eval and repl may both run, but never with stdin.
645653
// If stdin runs, eval and repl will not.

0 commit comments

Comments
 (0)