frontend-maven-plugin问题

使用frontend-maven-plugin插件打包web程序(vue或react等)时,出现报错

问题描述

  • 打包相关pom写法
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>12.8.3</version>
                <configuration>
                    <installDirectory>target</installDirectory>
                    <workingDirectory>src/main/direct-debit/</workingDirectory>
                </configuration>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>${node.version}</nodeVersion>
                            <npmVersion>${npm.version}</npmVersion>
                            <nodeDownloadRoot>https://npm.taobao.org/mirrors/node/</nodeDownloadRoot>
                            <npmDownloadRoot>http://registry.npmjs.org/npm/-/
                            </npmDownloadRoot>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                            <npmRegistryURL>https://registry.npm.taobao.org/</npmRegistryURL>
                        </configuration>
                    </execution>
                    <execution>
                        <id>npm build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
  • 点击maven install
    在这里插入图片描述
  • 错误信息
[ERROR]Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.6.0:npm (npm install) on project project-web: Failed to run task: 'npm install --registry=https://registry.npm.taobao.org/' failed. java.io.IOException: Cannot run program "D:\project-web\project-web-web\target\node\node.exe" (in directory "D:\project-web\project-web-web\src\main\fr-web"): CreateProcess error=193, %1 不是有效的 Win32 应用程序。 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.

根据报错信息发现,是说node不是有效的程序,在本地打开对应的node所在文件夹点击该程序发现存在版本不对,无法运行该程序

mvn clean package -e

如果需要查看更具体的错误信息,可以执行 mvn clean package -e 查看,会执行打包并显示更详细的错误信息

  • 错误信息
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.0:npm (npm install) on project project-web-web: Failed to run task: 'npm install --registry=https://registry.npm.taobao.org/' failed. java.io.IOException: Cannot run program
"D:\project-web\project-web-web\target\node\node.exe" (in directory "D:\project-web\project-web-web\src\main\fr-web"): CreateProcess error=193, %1 不是有效的 Win32 应用程
序。 -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.0:npm (npm install) on project project-web-web: Failed to run task

CreateProcess error=193, %1 不是有效的 Win32 应用程序。

你可以在本地执行以上命令,打开生成的target所在目录,点击其中node.exe程序,发现无法执行,下载的node.exe版本,不是window所对应的可执行程序,因此出现该问题

然后尝试发现在12.3.1能够下载正常可执行版本,12.18.3版本无法下载对应所需正常版本,14.9.0也可以下载对应版本,因此分析可能是12.8.3版本有问题,跳过非正常版本

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐