Skip to content
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

Investigate why spawnSync without shell: true results in ENOENT for npm/yarn in some windows systems #16119

Closed
filipesilva opened this issue Nov 8, 2019 · 6 comments
Assignees
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Milestone

Comments

@filipesilva filipesilva added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity5: regression area: @angular/cli labels Nov 8, 2019
@ngbot ngbot bot modified the milestone: Backlog Nov 8, 2019
dgp1130 added a commit to dgp1130/angular-cli that referenced this issue Nov 8, 2019
…ted in a directory with spaces. (angular#16073)"

This reverts commit 217eb29.

Reverting as this is breaking some Windows/CI builds. See angular#16119.
@alan-agius4
Copy link
Collaborator

alan-agius4 commented Nov 11, 2019

From: https://nodejs.org/dist/latest-v10.x/docs/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows

The importance of the distinction between child_process.exec() and child_process.execFile() can vary based on platform. On Unix-type operating systems (Unix, Linux, macOS) child_process.execFile() can be more efficient because it does not spawn a shell by default. On Windows, however, .bat and .cmd files are not executable on their own without a terminal, and therefore cannot be launched using child_process.execFile(). When running on Windows, .bat and .cmd files can be invoked using child_process.spawn() with the shell option set, with child_process.exec(), or by spawning cmd.exe and passing the .bat or .cmd file as an argument (which is what the shell option and child_process.exec() do). In any case, if the script filename contains spaces it needs to be quoted.

In order not to require shell in Windows. We'd need to change the spawn command to the below when running on windows

    const { status, stderr, stdout, error } = child_process_1.spawnSync('cmd.exe', ['/c', packageManager, ...installArgs, ...extraArgs], {
        stdio: 'pipe',
        encoding: 'utf8',
        cwd,
    });

That being said, I don't think we should do anything (ie: leave shell: true) as based on the docs, this is what shell option does.

When running on Windows, .bat and .cmd files can be invoked using child_process.spawn() with the shell option set, with child_process.exec(), or by spawning cmd.exe and passing the .bat or .cmd file as an argument (which is what the shell option and child_process.exec() do).

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Nov 11, 2019

Note: in the same there is also another spawnSync which uses shell

const { status, error } = spawnSync('node', argv, {
stdio: 'inherit',
shell: true,
env: {
...process.env,
NG_DISABLE_VERSION_CHECK: 'true',
NG_CLI_ANALYTICS: 'false',
},
});

@alan-agius4 alan-agius4 self-assigned this Nov 11, 2019
@filipesilva
Copy link
Contributor Author

SGTM, great work getting to the bottom of this!

@clydin
Copy link
Member

clydin commented Nov 11, 2019

npm is a batch file on windows?

@filipesilva
Copy link
Contributor Author

filipesilva commented Nov 11, 2019

Looks like it:

PS C:\Users\kamik> get-command npm

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     npm.cmd                                            0.0.0.0    C:\Program Files\nodejs\npm.cmd


PS C:\Users\kamik> get-command yarn

CommandType     Name                                               Version    Source
-----------     ----                                               -------    ------
Application     yarn.cmd                                           0.0.0.0    C:\Program Files (x86)\Yarn\bin\yarn.cmd

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Dec 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular/cli freq1: low Only reported by a handful of users who observe it rarely severity5: regression type: bug/fix
Projects
None yet
Development

No branches or pull requests

3 participants