git-for-windows / git

A fork of Git containing Windows-specific patches.
http://gitforwindows.org/
Other
8.34k stars 2.53k forks source link

Running npm inside Git Bash #3608

Closed PatrikTrefil closed 1 year ago

PatrikTrefil commented 2 years ago

Setup

$ git --version --build-options

** 
git version 2.34.1.windows.1
cpu: x86_64
built from commit: 2ca94ab318509b3c271e82889938816bad76dfea
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon 
**
$ cmd.exe /c ver

** Microsoft Windows [Version 10.0.22000.376] **
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

**
Editor Option: VIM
Custom Editor Path:
Default Branch Option:
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Merge
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Disabled
Enable FSMonitor: Disabled
**

Tried installing NodeJS using winget and default installer. Same with Git Bash

Details

mintty 3.5.2 (x86_54-pc-msys) [Windows 22000]

** npm --version **

version of npm

bash: /c/Users/patri/bin/npm: /usr/bin/env: bad interpreter: Permission denied

-

Running node in Git Bash works fine.

node

Running the following command in Git Bash never exits, but in WSL Bash starts node.

env node

Here is my $PATH given by Git Bash (might be relevant):

/c/Users/patri/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/patri/bin:/c/Python310/Scripts:/c/Python310:/c/Program Files/Common Files/Oracle/Java/javapath:/c/Program Files/Alacritty:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Windows/System32/OpenSSH:/c/Program Files/Calibre2:/c/Program Files/dotnet:/c/Program Files (x86)/Microsoft SQL Server/150/DTS/Binn:/c/Program Files/Azure Data Studio/bin:/c/Program Files/Microsoft SQL Server/Client SDK/ODBC/170/Tools/Binn:/c/Program Files (x86)/Microsoft SQL Server/150/Tools/Binn:/c/Program Files/Microsoft SQL Server/150/Tools/Binn:/c/Program Files/Microsoft SQL Server/150/DTS/Binn:/c/Strawberry/c/bin:/c/Strawberry/perl/site/bin:/c/Strawberry/perl/bin:/c/Program Files/Docker/Docker/resources/bin:/c/ProgramData/DockerDesktop/version-bin:/c/Program Files/PowerShell/7:/c/ProgramData/chocolatey/bin:/cmd:/c/Program Files/nodejs:/c/Users/patri/AppData/Local/Microsoft/WindowsApps:/c/Users/patri/AppData/Local/Programs/MiKTeX/miktex/bin/x64:/c/Users/patri/AppData/Local/Programs/Microsoft VS Code/bin:/c/Users/patri/.dotnet/tools:/c/Program Files/Azure Data Studio/bin:/c/Users/patri/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/Scripts:/c/Users/patri/AppData/Roaming/npm:/usr/bin/vendor_perl:/usr/bin/core_perl
PatrikTrefil commented 2 years ago

Using winpty to run npm:

$ winpty npm --version

** winpty: error: cannot start 'npm': Not found in PATH **
dscho commented 2 years ago

x86_54

That's a funny CPU architecture you got there 😁

bash: /c/Users/patri/bin/npm: /usr/bin/env: bad interpreter: Permission denied

This suggests to me that there is a problem with the first line of C:\Users\Patri\bin\npm. Can you investigate along those lines?

PatrikTrefil commented 2 years ago

Yeah, that was supposed to be x86_64 of course 😁

$ cat -A /c/Users/patri/bin/npm
**
#!/usr/bin/env node$
require('../lib/cli.js')(process)$

**

I tried running this script.

#!/usr/bin/env node
console.log("hello world");

Everything worked fine.

rimrul commented 2 years ago

Could be an issue with eols? Does /c/Users/patri/bin/npm have crlf line endings, while the other script is just lf?

PatrikTrefil commented 2 years ago

That's not it. The other script has the same line endings (lf).

$ cat -A test

**
#!/usr/bin/env node$
console.log("hello world");$
**
dscho commented 2 years ago

Yeah, that was supposed to be x86_64 of course 😁

$ cat -A /c/Users/patri/bin/npm
**
#!/usr/bin/env node$
require('../lib/cli.js')(process)$

**

I tried running this script.

#!/usr/bin/env node
console.log("hello world");

Everything worked fine.

If I were you, I would insert a console.log() into /c/Users/patri/bin/npm to see whether the script is launched at all, and maybe the error occurs later. If it is not launched at all, I would then edit the second script by inserting that require() call. Break it down, like.

dscho commented 1 year ago

Closing as stale.