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

[BUG] "command not found" when running script with bash as script-shell on Windows #90

Closed
1 task done
stevenwdv opened this issue Jun 29, 2022 · 1 comment · Fixed by #96
Closed
1 task done
Labels
Needs Triage needs an initial review

Comments

@stevenwdv
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

On Windows, if Bash/sh is set as script-shell for npm and a script is run, it gives the following error:

/usr/bin/bash: C:UsersMeAppDataLocalTempmy-script-1656497236474.sh: command not found

It appears that backslashes in paths are not escaped or paths transformed.

This bug is likely introduced in run-script 4.1.0:

write scripts to a file and run that instead of passing scripts as a single string 24c5165

Expected Behavior

It should run the script fine

Steps To Reproduce

  1. Install npm 8.13.0 or later
  2. Put some script in a packages.json, "the-script": "echo hi" will do
  3. Run npm config set script-shell "C:\Program Files\Git\bin\sh.exe" if you have Git installed, or use the path to sh/bash for your MSYS2 installation
  4. Run npm run the-script
  5. Get the error shown above

Environment

  • npm: 8.13.0, 8.13.1 (8.12.2 and below work fine)
  • Node: 18.4.0
  • OS: Windows 10
@stevenwdv stevenwdv added the Needs Triage needs an initial review label Jun 29, 2022
@schmidtk
Copy link

schmidtk commented Jul 7, 2022

Confirmed on Windows 10 with Git Bash, and npm's script-shell set to use bash.

The script generated by run-script uses a Windows-style path, and the single backslashes are treated as escape characters by Git Bash. This causes the separators to be dropped from the path, and the script fails to run with "command not found" due to the invalid path.

As noted, npm 8.12.2 works as it uses an older version of run-script. Our team is using npm workspaces, which presented another problem when sub-dependencies (@semantic-release/npm in our case) depend on npm. The sub-dependency was hoisted to <project>/node_modules/npm which was used by npm run scripts in <project>/package.json.

Our current workaround to the above problem is to add [email protected] as a direct dependency of our project, so that version will be hoisted to the root node_modules. A complete solution would require updating run-script to escape the path properly in this environment.

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

Successfully merging a pull request may close this issue.

2 participants