Skip to content

[BUG] npm start fails with ERR_INVALID_ARG_TYPE due to missing ComSpec on Windows #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
SongMinQQ opened this issue Apr 3, 2025 · 1 comment
Open
1 task done
Labels
Bug thing that needs fixing Needs Triage needs an initial review

Comments

@SongMinQQ
Copy link

SongMinQQ commented Apr 3, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

2025-04-03T00_27_13_487Z-debug-0.log

This is caused by the spawnWithShell function expecting the environment variable ComSpec to be defined (usually cmd.exe on Windows). However, in some Windows environments, ComSpec might be undefined.

Image

Actual behavior:

Fails with ERR_INVALID_ARG_TYPE.

Proposed solution:

Modify the spawnWithShell function as follows:

if (command === true) {
  command = process.platform === 'win32'
    ? (process.env.ComSpec || 'C:\\Windows\\System32\\cmd.exe')
    : 'sh'
}

Expected Behavior

It should default to C:\Windows\System32\cmd.exe if ComSpec is undefined, allowing the command to succeed.

Steps To Reproduce

  1. On Windows, ensure the environment variable ComSpec is unset or missing.
  2. Run an npm command like npm start that uses opts.shell = true internally.
  3. Observe the above error.

Environment

  • Node: v22.14.0 (managed by nvm-windows)
  • npm: v11.2.0
  • OS: Windows 10
  • promise-spawn version: (version used by npm internally)
  • platform: LG gram
@SongMinQQ SongMinQQ added Bug thing that needs fixing Needs Triage needs an initial review labels Apr 3, 2025
@SongMinQQ
Copy link
Author

In addition to the approach I suggested, it might also be helpful to display a clear error message to the user when the required environment variable is not set.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs an initial review
Projects
None yet
Development

No branches or pull requests

1 participant