执行目标 org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (npm run build) 失败,项目名为 npm。

4
我是一个有用的助手,可以帮您进行翻译。
我正在尝试将我的Web应用程序部署到Heroku。为了运行我的应用程序,我需要执行以下操作:
   npm run build

所以我需要在Heroku安装npm。我找到了可以完成此操作的maven插件和执行脚本的插件。

   <build>
    <plugins>
        <plugin>
            <groupId>com.github.eirslett</groupId>
            <artifactId>frontend-maven-plugin</artifactId>
            <!-- Use the latest released version:
            https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
            <version>1.7.5</version>
            <executions>
                <execution>
                <!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
                <id>install node and npm</id>
                <goals>
                    <goal>install-node-and-npm</goal>
                </goals>
                <!-- optional: default phase is "generate-resources" -->
                <phase>generate-resources</phase>
            </execution>

            </executions>
            <configuration>
                <nodeVersion>v11.15.0</nodeVersion>
                <npmDownloadRoot>https://nodejs.org/dist/v6.11.3/win-x64/node.exe</npmDownloadRoot>

            </configuration>

        </plugin>                     
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.3.2</version>
            <executions>
                <execution>
                    <id>npm run build</id>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <phase>compile</phase>
                    <configuration>
                        <executable>npm</executable>
                        <arguments>
                            <argument>run</argument>
                            <argument>build</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

但是当我尝试将其推送到Heroku时,出现以下错误:

在项目vstup上执行命令org.codehaus.mojo:exec-maven-plugin:1.3.2:exec (npm run build)失败:无法运行程序“npm”(在目录“/tmp/build_6883506630fbb2f73ce1bcb9a5d6cf3d”中):错误=2,没有那个文件或目录 -> [帮助 1]

该错误的意思是你所需要的npm程序没有被找到。可能是由于在Heroku上缺少必要的依赖项或配置所导致的。请检查您的依赖关系和配置是否正确,并确保所有必要的组件都已正确安装。
1个回答

0
今天我在使用GitLab-ci和Spring Boot应用程序时遇到了同样的错误。
我不得不运行“before script”来安装缺失的npm:
before_script:
   - 'apt-get update'
   - 'apt-get install -y npm'
script:
   - 'mvn deploy'

在运行 Maven exec 插件之前,这将安装 npm 可执行文件。

我的 mvn 插件配置如下:

           <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
                <workingDirectory>${project.basedir}/src/main/frontend</workingDirectory>
            </configuration>
            <executions>
                <execution>
                    <id>exec-npm-install</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <executable>npm</executable>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
           </plugin>

提示:

  • 也许您可以尝试使用after_scriptbefore_script运行ls -Ra,查看是否缺少文件或目录,但这不是我的情况

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接