4

I have npm and node installed (tried NVM for Windows and direct installations).

When running 'npm -v' or 'node -v' in Git Bash everythings works fine. But when I try to run 'npm run dev' (or any other command) the output says that 'node command is not recognized'.

In other shells (CMD/Powershell) everything works fine.

I've checked Path variable in Windows, Path variable in Git Bash, everything seems to be correct.

Error screenshot Path variable screenshot

Path variables cmd/procmon

Any help appreciated.

p.s. While I was trying to find an answer I saw the same question from @jameseg , maybe if he sees this one he could help.

10
  • 1
    Possible duplicate of: stackoverflow.com/questions/58102323/… Commented Jun 23, 2020 at 8:38
  • @Sergio thank you, looks like it is. But that question wasn't answered and was asked a year ago. Maybe I have more luck Commented Jun 23, 2020 at 8:57
  • Does this answer your question? How come npm install doesn't work on git bash Commented Jun 23, 2020 at 9:01
  • @jpnadas Nope, I've tried all of the suggested options Commented Jun 23, 2020 at 9:14
  • 1
    @CherryDT added screenshot of %path% from cmd and procmon Commented Jun 29, 2020 at 9:57

1 Answer 1

4

Your PATH environment variable is quite a mess. It has duplicate entries, also has an entry C:\Program Files\nodejs\node.exe which is not valid because it should be a folder, not a file, and it has . in the middle which doesn't make much sense either.

But the main problem is that it has a stray doublequote, after C:\Program Files\Java\jdk-13.0.1\bin:

stray doublequote

With this, effectively all the paths after it are ignored, because they are treated as part of one big quoted string (which is implicitly terminated by the end of the variable data).


To illustrate what I mean, consider this example:

This correct PATH variable...

C:\a;C:\b;"C:\c 123";C:\d;C:\e

...is interpreted as:

C:\a
C:\b
C:\c 123
C:\d
C:\e

But, this bad PATH variable where I deleted one of the quotes...

C:\a;C:\b;C:\c 123";C:\d;C:\e

...is interpreted like this:

C:\a
C:\b
C:\c 123";C:\d;C:\e

This may at first make only half sense, but it's because of the quirky way Windows parses this variable: When encountering a doublequote, it's removed from the result but toggles a flag that says whether we are now inside a quoted string. And when the flag is set, semicolons are ignored. So even if the stray quote is at the end of a path (or in the middle of it), it will have the effect of essentially quoting the rest of the variable data until the next doublequote or the end of the data.

Confusingly, you may still have where node report that it found node, because the where.exe tool does its own parsing, in a slightly different way (ignoring quotes), so you cannot rely on its output! (For example, try set PATH=c:\win""dows. where explorer will say it can't be found, yet explorer will work to open Explorer. You get the opposite with something like set PATH=x"y;c:\windows - where explorer will list c:\windows\explorer.exe, yet explorer will not work.) The reason why it works in Git Bash is probably the same: when the environment variables are translated to UNIX paths, they are parsed slightly differently than Windows would do it itself, inadvertently correcting the problematic entry in the process.

So, the solution is to remove this doublequote from your path variable.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, it worked! Thank you for your patienсe and attention, I would never solve this by myself.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.