diff --git a/cli/tests/unit_node/process_test.ts b/cli/tests/unit_node/process_test.ts index 461afb9f67..bcb7a97679 100644 --- a/cli/tests/unit_node/process_test.ts +++ b/cli/tests/unit_node/process_test.ts @@ -774,3 +774,15 @@ Deno.test({ assertEquals(process.title, "deno"); }, }); + +Deno.test({ + name: "process.argv[1] in Worker", + async fn() { + const worker = new Worker( + `data:text/javascript,import process from "node:process";console.log(process.argv[1]);`, + { type: "module" }, + ); + await delay(10); + worker.terminate(); + }, +}); diff --git a/ext/node/polyfills/process.ts b/ext/node/polyfills/process.ts index c7c22b562d..64a3ef31be 100644 --- a/ext/node/polyfills/process.ts +++ b/ext/node/polyfills/process.ts @@ -873,7 +873,7 @@ internals.__bootstrapNodeProcess = function ( // Overwrites the 2st item with getter. Object.defineProperty(argv, "1", { get: () => { - if (Deno.mainModule.startsWith("file:")) { + if (Deno.mainModule?.startsWith("file:")) { return pathFromURL(new URL(Deno.mainModule)); } else { return join(Deno.cwd(), "$deno$node.js");