Fix: fallback for missing process.env.ComSpec on Windows #8205
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses a bug in the npm run-script chain on Windows when running commands such as
npm startin a React project under Node.js 22.14.0 LTS.In our environment, the environment variable
process.env.ComSpec—which is typically used to determine the default shell (e.g., "C:\Windows\System32\cmd.exe")—is missing.As a result, the code in the
spawnWithShellfunction falls back to an undefined value for the shell command.This causes the subsequent call to
child_process.spawn()to receiveundefinedas the file argument, leading to the error:The "file" argument must be of type string. Received undefined
The fix implemented in this PR adds a fallback so that if
process.env.ComSpecis not defined, it defaults to using"cmd.exe". This ensures that the command is properly resolved and that the shell execution chain works as expected.Changes made:
spawnWithShellfunction, the code is modified as follows:References