6

I am on a Windows 7 computer and I've been given code that I have to run "mvn install" on to build the app. When I do this, I get the following error:

Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (npm-install) on project [project]: Command execution failed.: Cannot run program "npm" (in directory "C:\Users\path\to\a\folder"): CreateProcess error=2, The system cannot find the file specified

The app itself is split into several parts, one of which is an angular app that npm is being used for.

I've tried installing nodejs (which I'm not very familiar with) and included it in the PATH, but the same error happened anyway. Shouldn't maven take care of the need for installing it?

Any advice on how to resolve this is appreciated.

syim
  • 501
  • 1
  • 4
  • 16

3 Answers3

5

There are two ways to correct this (the second method is preferable if you build the projects targeting linux and windows both. Moreover, also if the no. of pom files is also large):

  1. Change in pom file if using maven see (https://stackoverflow.com/a/40390500/4282901)

               <executions>
                <execution>
                  <id>npm install</id>
                  <phase>generate-sources</phase>
                  <goals>
                     <goal>exec</goal>
                  </goals>
                  <configuration>
                     <executable>npm.cmd</executable>
                     <arguments>
                        <argument>--loglevel</argument>
                        <argument>error</argument>
                        <argument>install</argument>
                     </arguments>
                  </configuration>
               </execution>
    
    1. In the directory where node is installed rename the batch file so that the existing npm.cmd file is picked. See screenshot below: rename npm batch to _npm so that npm.cmd is picked
Syed Osama Maruf
  • 1,895
  • 2
  • 20
  • 37
  • 1
    To clarify, rename the npm (without any extension) file. It's not a bat file, but renaming it worked for me. – Malcolm Anderson Dec 05 '19 at 22:35
  • Renaming worked for me. But i cannot tell my 50 members team to rename. Any alternate solution? @MalcolmAnderson – Laxman Spidey Nov 20 '20 at 13:17
  • @LaxmanSpidey, I guess you could write a bat file (or shell script) that would do the renaming for you, but hopefully all you would have to do is change the file name in the code repository and tell everyone to pull latest. Your team does have *everything* under version control don't they? – Malcolm Anderson Nov 22 '20 at 06:19
  • 1
    Finally, solved it by using plugin version 1.6.0. Thanks. Source: https://stackoverflow.com/questions/22708255/cannot-run-program-npm-in-directory/39407412#comment86020329_39407412 – Laxman Spidey Dec 16 '20 at 08:27
2

Install NodeJS and angular cli

Visit https://nodejs.org/en/ and install the latest x64 version.

After nodejs installed, then using below command to install angular/cli.

npm install -g @angular/cli
Mario Petrovic
  • 7,500
  • 14
  • 42
  • 62
1

If NodeJS installed when the IDE is open, it might be required to restart IDE to find the path of binary.