3

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.
matisa
  • 143

3 Answers3

4

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.

bvdb
  • 181
0

The problem is that your NPM is not visible by Jenkins. You can write the CMD command using the full path to npm.exe:

C:\Users\USERNAME\Desktop\node-v10.15.3-win-x86\node.exe run build

To see node version:

C:\Users\USERNAME\Desktop\node-v10.15.3-win-x86\node.exe -v
davidbaumann
  • 2,289
I.kora
  • 1
0

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

matisa
  • 143