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

Workaround for node 18.6.0 bug #1838

Merged
merged 3 commits into from Jul 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions dist-raw/runmain-hack.js
@@ -0,0 +1,9 @@
const {pathToFileURL} = require('url');

// Hack to avoid Module.runMain on node 18.6.0
// Keeping it simple for now, isolated in this file.
// Could theoretically probe `getFormat` impl to determine if `import()` or `Module._load()` is best
// Note that I attempted a try-catch around `Module._load`, but it poisons some sort of cache such that subsequent `import()` is impossible.
exports.run = function(entryPointPath) {
import(pathToFileURL(entryPointPath));
}
10 changes: 9 additions & 1 deletion src/bin.ts
Expand Up @@ -639,7 +639,15 @@ function phase4(payload: BootstrapState) {

// Execute the main contents (either eval, script or piped).
if (executeEntrypoint) {
Module.runMain();
if (
payload.isInChildProcess &&
versionGteLt(process.versions.node, '18.6.0')
) {
// HACK workaround node regression
require('../dist-raw/runmain-hack.js').run(entryPointPath);
} else {
Module.runMain();
}
} else {
// Note: eval and repl may both run, but never with stdin.
// If stdin runs, eval and repl will not.
Expand Down