node.js - Maven 未能执行目标 - 无法运行程序 npm

标签 node.js windows angular maven npm

我使用的是 Windows 7 计算机,我已获得必须运行“mvn install”才能构建应用程序的代码。当我这样做时,出现以下错误:

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

应用程序本身分为几个部分,其中一个是使用 npm 的 Angular 应用程序。

我已经尝试安装 nodejs(我不是很熟悉)并将其包含在 PATH 中,但还是发生了同样的错误。 maven 不应该考虑安装它的需要吗?

如有任何关于如何解决此问题的建议,我们将不胜感激。

最佳答案

有两种方法可以纠正这个问题(如果你同时构建针对 linux 和 windows 的项目,第二种方法更可取。此外,如果 pom 文件的数量也很大):

  1. 如果使用 maven,请更改 pom 文件,请参阅 ( 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. 在安装 Node 的目录中重命名批处理文件,以便选择现有的 npm.cmd 文件。请参见下面的屏幕截图: rename npm batch to _npm so that npm.cmd is picked

关于node.js - Maven 未能执行目标 - 无法运行程序 npm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48156538/

相关文章:

node.js - 找不到模块 'angular2/angular2'

python - 在opencv4nodejs中如何在调用drawRectangle时设置Alpha

ruby-on-rails - sublime text ruby​​ 测试窗口找不到路径

c++ - 为什么我用 WriteFile 写入文件的每个字符之间都有一个空白?

Java 8 Update 60 减少可用堆内存

Angular Material 对话框没有响应

angular - 当用户单击 mat-calendar 中的月份导航时,如何检索月份和年份值?

来自 Github 的 Angular 模块,如何集成到我的模块中?

javascript - npm 错误!无关的 : pug@2. 0.0-alpha6

node.js - 为什么需要在 git repo 中删除 node_modules 文件夹?