Saturday, January 27, 2024

[SOLVED] Git Bash can't find node.js, even though it is in my Path and it works in Powershell

Issue

I'm having trouble using Node.js on Git Bash (on Windows 11). When I run

npm install --save puppeteer

or a similar command, I get the following error message:

npm ERR! code 1
npm ERR! path C:\Users\{user}\git-repos\book-scraper\node_modules\puppeteer
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node install.js
npm ERR! 'node' is not recognized as an internal or external command,
npm ERR! operable program or batch file.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\{user}\AppData\Local\npm-cache\_logs\2022-08-18T20_26_25_630Z-debug-0.log

I double checked that Node was included in my Path variables. I have tried including both path to the node directory and to node.exe. When I run the same command in a Powershell or Windows Terminal the command works without issues. I also checked the log - here is the relevant part of the log file:

365 verbose pkgid [email protected]
366 verbose cwd C:\Users\{user}\git-repos\book-scraper
367 verbose Windows_NT 10.0.22000
368 verbose node v16.15.0
369 verbose npm  v8.17.0
370 error code 1
371 error path C:\Users\{user}\git-repos\book-scraper\node_modules\puppeteer
372 error command failed
373 error command C:\WINDOWS\system32\cmd.exe /d /s /c node install.js
374 error 'node' is not recognized as an internal or external command,
374 error operable program or batch file.
375 verbose exit 1

I'd appreciate any help anyone can offer!


Solution

Instead of opening git bash from a Windows explorer contextual menu, open a Windows Terminal (where node does work) and:

  • make sure your %PATH% also includes C:\Program Files\Git\bin\ (before C:\Windows\System32)
  • type "bash" (to enter a Git bash session)
  • check if node is recognized with which node


Answered By - VonC
Answer Checked By - Senaida (WPSolving Volunteer)