Skip to content

Conversation

@SongMinQQ
Copy link
Contributor

@SongMinQQ SongMinQQ commented Aug 28, 2025

What / Why


issue No. #131

On Windows, some environments don’t expose process.env.ComSpec.
When that happens, the shell selection logic ends up passing undefined to child_process.spawn(), throwing ERR_INVALID_ARG_TYPE (“file” must be a string).

This PR updates the shell resolution so that on win32 we fallback to "cmd.exe" when process.env.ComSpec is missing, while preserving existing behavior on:

non-Windows (sh) and

Windows when ComSpec is set (still honored).

Rationale: cmd.exe is the standard Windows shell and is present by default. This change prevents crashes in real-world setups without altering behavior for users who explicitly define ComSpec.

Change summary

Update shell selection:

command = process.platform === 'win32'
  ? (process.env.ComSpec || 'cmd.exe')
  : 'sh'

Add/adjust tests to cover the “missing ComSpec” case on Windows.

Tests

os: Windows 10 (WSL2)
node: 22.14.0
npm: 11.2.0
image

References

Prior attempt on npm/cli was closed with a maintainer note that this logic lives in @npmcli/promise-spawn (npm vendors this dependency).
GitHub

@SongMinQQ SongMinQQ requested a review from a team as a code owner August 28, 2025 07:37
@SongMinQQ SongMinQQ force-pushed the fix/win-shell-comspec branch from 3241d57 to 76f4d45 Compare August 28, 2025 16:46
@owlstronaut owlstronaut changed the title Fix: fallback for missing process.env.ComSpec on Windows fix: fallback for missing process.env.ComSpec on Windows Aug 28, 2025
@owlstronaut owlstronaut self-assigned this Aug 28, 2025
@owlstronaut
Copy link
Contributor

You can ignore the CodeQL failure. Next step is for me to actually review it

@owlstronaut owlstronaut merged commit c12e015 into npm:main Aug 28, 2025
19 of 21 checks passed
@github-actions github-actions bot mentioned this pull request Aug 28, 2025
owlstronaut pushed a commit that referenced this pull request Aug 28, 2025
🤖 I have created a release *beep* *boop*
---


## [8.0.3](v8.0.2...v8.0.3)
(2025-08-28)
### Bug Fixes
*
[`c12e015`](c12e015)
[#137](#137) fallback for
missing process.env.ComSpec on Windows (#137) (@SongMinQQ)
### Chores
*
[`ddef6b2`](ddef6b2)
[#133](#133) postinstall
workflow updates (#133) (@owlstronaut)
*
[`32390d6`](32390d6)
[#136](#136) bump
@npmcli/template-oss from 4.24.4 to 4.25.0 (#136) (@dependabot[bot],
@npm-cli-bot)

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants