child_process: empty options.env results in ENOMEM error #29008
Closed
Description
- Version: v10.16.1
- Platform: Windows 10 x64 Version 1803 (OS Build 17134.885)
- Subsystem: child_process
When calling another process, the exec
and execSync
commands fail with a ENOMEM error when using an empty object for the options.env
variable. Using any non-undefined
value at all in the env
object makes the call work again.
const { execSync } = require('child_process');
execSync('node', {env: {}}) // Fails with ENOMEM error
execSync('node', {env: {x: undefined}}) // Fails with ENOMEM error
execSync('node', {env: {x: 0}}) // Works
The error trace:
Thrown:
{ Error: spawnSync C:\WINDOWS\system32\cmd.exe ENOMEM
at Object.spawnSync (internal/child_process.js:1002:20)
at spawnSync (child_process.js:614:24)
at execSync (child_process.js:661:13)
errno: 'ENOMEM',
code: 'ENOMEM',
syscall: 'spawnSync C:\\WINDOWS\\system32\\cmd.exe',
path: 'C:\\WINDOWS\\system32\\cmd.exe',
spawnargs: [ '/d', '/s', '/c', '"node"' ],
error: [Circular],
status: null,
signal: null,
output: null,
pid: 0,
stdout: null,
stderr: null }
This did not happen in v10.15.*, and seems to affect v10.16.0 as well.