From 60e112d8a5bde9fdcb632e8860157c7bd52e2e6c Mon Sep 17 00:00:00 2001 From: "shuwen.wu" Date: Wed, 2 Sep 2026 19:39:41 +0800 Subject: [PATCH] child_process: support execArgv in spawn() The execArgv option passed to spawn() was being silently ignored. This commit adds proper handling of execArgv in normalizeSpawnArguments(), prepending the execArgv values to the args array before argv0/file. Fixes: https://github.com/nodejs/node/issues/65725 PR-URL: https://github.com/nodejs/node/pull/65726 --- doc/api/child_process.md | 1 + lib/child_process.js | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/doc/api/child_process.md b/doc/api/child_process.md index 138fb52f8612..e21fa81363a9 100644 --- a/doc/api/child_process.md +++ b/doc/api/child_process.md @@ -695,6 +695,7 @@ changes: * `env` {Object} Environment key-value pairs. **Default:** `process.env`. * `argv0` {string} Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` if not specified. + * `execArgv` {string\[]} List of string arguments passed to the executable. * `stdio` {Array|string} Child's stdio configuration (see [`options.stdio`][`stdio`]). * `detached` {boolean} Prepare child process to run independently of diff --git a/lib/child_process.js b/lib/child_process.js index 887f5668e37a..e517966147b4 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -691,6 +691,13 @@ function normalizeSpawnArguments(file, args, options) { } } + // Handle execArgv - prepend to args if provided + if (options.execArgv != null) { + validateArray(options.execArgv, 'options.execArgv'); + validateArgumentsNullCheck(options.execArgv, 'options.execArgv'); + args = [...options.execArgv, ...args]; + } + if (typeof options.argv0 === 'string') { ArrayPrototypeUnshift(args, options.argv0); } else { @@ -788,6 +795,7 @@ function abortChildProcess(child, killSignal, reason) { * cwd?: string | URL; * env?: Record; * argv0?: string; + * execArgv?: string[]; * stdio?: Array | string; * detached?: boolean; * uid?: number;