Git Bash throws stdin undefined error when running npm commands on Windows

I’m encountering a strange issue with npm when using Git Bash terminal on my Windows machine. Every time I try running any npm command, I get this error message:

npm ERR! Cannot read properties of undefined (reading 'stdin')

This problem just started happening recently. Everything was working perfectly fine until a couple days ago. The weird thing is that npm works without any issues when I use Command Prompt or PowerShell instead of Git Bash.

I’ve already tried several troubleshooting steps including re-cloning my repositories, removing node_modules folder and package-lock.json file, and clearing the npm cache, but none of these solutions fixed the problem.

As a temporary workaround, I downgraded my Node.js version which seemed to resolve the issue for now. However, I’m still curious about what might have caused this compatibility problem between Git Bash and npm in the first place.

had similar issue last week, turns out git bash was using different terminal settings after windows update. try running winpty npm instead of just npm - worked for me when regular npm commands failed with stdin errors.

I ran into this exact problem after a recent Git for Windows update and found that the issue was related to how npm handles input/output streams in Git Bash’s terminal environment. What solved it for me was reinstalling the latest version of Git for Windows completely rather than just updating it. Sometimes the update process doesn’t properly configure all the terminal emulation components. Before doing a full reinstall, you might also want to check if you have any custom aliases or configurations in your .bashrc or .bash_profile that could be interfering with npm’s stdin handling. The reason Command Prompt and PowerShell work fine is because they use native Windows terminal APIs, while Git Bash uses MSYS2 which creates a different terminal environment that can conflict with Node.js processes expecting standard Windows behavior.

This typically happens when there’s a conflict between Git Bash’s pseudo-terminal handling and npm’s attempt to access stdin. I encountered this exact same error after updating Git for Windows to version 2.42 or later. The issue stems from changes in how Git Bash emulates terminal behavior on Windows systems. What fixed it for me was modifying the MSYS environment variable - you can try setting MSYS=enable_pcon in your Git Bash profile or running export MSYS=enable_pcon before executing npm commands. Another approach that worked was updating Git Bash to the latest version, as newer releases have addressed some of these terminal compatibility issues. The reason your downgrade worked is because older Node versions handle the pseudo-terminal differently.