'npm' is not recognized as an internal or external command in jenkins only
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.
Related videos on Youtube
matisa
Updated on September 18, 2022Comments
-
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 about 5 yearsAs per my comment on Stackoverflow on this duplicate question, I suggest you read this
-
matisa about 5 yearsTnx, already did. Actually the reason was that the file was npm.cmd. Called it this way and it worked.
-
Gerhard about 5 yearsSo then perhaps removing the question would be best.
-
matisa about 5 yearsDon't think so. I searched a lot, and this might help someone else.
-
Gerhard about 5 yearsWhat might help them? There is no valid answer to this, a question with no answer is no help...
-
matisa about 5 yearsBut 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 about 5 yearsmy 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 about 5 yearsI 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 almost 4 yearsI had the same idea, but didn't fix it for me
-
matisa almost 4 yearsmaybe you need to set the path to npm or add the full path to your script. Can you call npm directly in cmd?
-
bvdb almost 4 yearsI 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.