'npm' is not recognized as an internal or external command in jenkins only

12,461

Solution 1

Solved the problem by tuning the command this way: npm.cmd run build

Solution 2

I had the same problem, next tried renaming it to npm.cmd which didn't work neither, then tried a full path, which worked at first. But next thing I knew, the npm script had dependencies to other processes which couldn't be found neither. It took me a while to realize what was going on, but it made perfect sense.

In windows, whenever you install a command line application it adds its installation folders to the PATH variable. And that is also the case for node, npm, ng and many more. There is a tricky thing with the PATH variable though, it doesn't just refresh for active terminals or processes. So, whenever you install something to it, you need to close and reopen your terminals.

And actually the same goes for your running jenkins. It also needs to be restarted in order to have its PATH variable updated.

So chances are that you just installed node or npm but you didn't restart your system yet, and didn't restart your jenkins server. In that case, it will give you exactly the error mentioned above.

All my issues were solved simply by restarting the jenkins service.

Share:
12,461

Related videos on Youtube

matisa
Author by

matisa

Updated on September 18, 2022

Comments

  • matisa
    matisa over 1 year

    EDIT: if any one else will have this problem. The file was cmd, so calling npm.cmd fixed the problem.

    I nee to preform :

    npm run build
    

    It's a part of a Jenkins deploy. I have created a batch file that preform all the npm actions. When I run the command or the batch file from CMD it run just fine, no meter the path a execute if from. But when I execute if from "Execute windows batch command" I get:

    > npm run build:dev 
    'npm' is not recognized as an internal or external command,
    operable program or batch file.
    
    • Gerhard
      Gerhard about 5 years
      As per my comment on Stackoverflow on this duplicate question, I suggest you read this
    • matisa
      matisa about 5 years
      Tnx, already did. Actually the reason was that the file was npm.cmd. Called it this way and it worked.
    • Gerhard
      Gerhard about 5 years
      So then perhaps removing the question would be best.
    • matisa
      matisa about 5 years
      Don't think so. I searched a lot, and this might help someone else.
    • Gerhard
      Gerhard about 5 years
      What might help them? There is no valid answer to this, a question with no answer is no help...
    • matisa
      matisa about 5 years
      But there is. From cmd I could call npm with no problem, direct of in batch script. But in jenkins it failed with the error. Only when I called it npm.cmd it worked.
    • Gerhard
      Gerhard about 5 years
      my point is, there is no answer to this question, the answer below is not really the solution that resolved your issue..was it?? So a question with no answer is not useful. unless the answer below solved the issue and it was marked as correct, then it might be useful.
    • matisa
      matisa about 5 years
      I will edit me question or post an edit to the answer. And any way many times I have found the correct answer in comments.
  • bvdb
    bvdb almost 4 years
    I had the same idea, but didn't fix it for me
  • matisa
    matisa almost 4 years
    maybe you need to set the path to npm or add the full path to your script. Can you call npm directly in cmd?
  • bvdb
    bvdb almost 4 years
    I actually tried setting the full path, but then the next thing was that it indirectly wanted to invoke the "node" process and it couldn't find that neither. . Actually I found a solution and will post it.