Skip to content

await Promise.resolve("import('./mod.mjs')").then(eval) rejects/segfaults in REPL #43681

@nicolo-ribaudo

Description

@nicolo-ribaudo

Version

v18.4.0

Platform

Linux nic-XPS-15-9570 5.15.0-40-generic #43-Ubuntu SMP Wed Jun 15 12:54:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

modules

What steps will reproduce the bug?

Have an empty mod.mjs file, and a main.mjs file with the following contents:

console.log(1, await import("./mod.mjs"));
console.log(2, await eval(`import("./mod.mjs")`));
console.log(3, await (0, eval)(`import("./mod.mjs")`));
console.log(4, await Promise.resolve(`import("./mod.mjs")`).then(s => eval(s)));
console.log(5, await Promise.resolve(`import("./mod.mjs")`).then(s => (0,eval)(s)));
console.log(6, await Promise.resolve(`import("./mod.mjs")`).then(eval));

If you run node main.mjs, it works.

However, if you open the REPL and copy-paste-run the first five lines one by one. Now kill the REPL, restart it, and run the sixth line: it throws

Uncaught TypeError: Invalid host defined options
    at eval (eval at processTicksAndRejections (node:internal/process/task_queues:95:5), <anonymous>:1:1)
    at eval (<anonymous>)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async REPL2:1:39

If you don't restart the REPL before running the sixth line, it almost always crashes with a segfault:

[1]    85373 segmentation fault (core dumped)  node

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

I assume that the last line should work in the REPL, because it works in a file and because all the other lines work in the REPL.
Even if the error is expected for some reason, it shouldn't segfault.

What do you see instead?

/

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.replIssues and PRs related to the REPL subsystem.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions