Search code examples
angularspringmavenmaven-frontend-plugin

frontend-maven-plugin when it runs npm run build can't find package.json file


I'm building an app with spring boot backend and angular frontend. I am using frontend-maven-plugin to build the frontend when running maven When I run mvn spring-boot:run i get this error:

mvn spring-boot:run
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.demo:investmentswallet >------------------
[INFO] Building investmentswallet 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.2.6.RELEASE:run (default-cli) > test-compile @ investmentswallet >>>
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:install-node-and-npm (install-npm) @ investmentswallet ---
[INFO] Node v12.16.3 is already installed.
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:npm (npm-install) @ investmentswallet ---
[INFO] Running 'npm install' in C:\Users\Michal\Desktop\InvestmentsWallet
[INFO] npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\Michal\package.json'
[INFO] npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Michal\package.json'
[INFO] npm WARN @auth0/[email protected] requires a peer of @angular/common@^6.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN [email protected] requires a peer of gatsby@^2.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN [email protected] requires a peer of react@>=15.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN [email protected] requires a peer of react@^0.13.0 || ^0.14.0 || ^15.0.0 || ^16.0.0 but none is installed. You must install peer dependencies yourself.
[INFO] npm WARN Michal No description
[INFO] npm WARN Michal No repository field.
[INFO] npm WARN Michal No README data
[INFO] npm WARN Michal No license field.
[INFO]
[INFO] audited 73 packages in 0.853s
[INFO] found 1 low severity vulnerability
[INFO]   run `npm audit fix` to fix them, or `npm audit` for details
[INFO]
[INFO] --- frontend-maven-plugin:1.9.1:npm (npm run build) @ investmentswallet ---
[INFO] Running 'npm run build' in C:\Users\Michal\Desktop\InvestmentsWallet
[INFO] npm ERR! code ENOENT
[INFO] npm ERR! syscall open
[INFO] npm ERR! path C:\Users\Michal\package.json
[INFO] npm ERR! errno -4058
[INFO] npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\Michal\package.json'
[INFO] npm ERR! enoent This is related to npm not being able to find a file.
[INFO] npm ERR! enoent
[INFO]
[INFO] npm ERR! A complete log of this run can be found in:
[INFO] npm ERR!     C:\Users\Michal\AppData\Roaming\npm-cache\_logs\2020-05-24T13_11_03_257Z-debug.log
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.802 s
[INFO] Finished at: 2020-05-24T15:11:03+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.eirslett:frontend-maven-plugin:1.9.1:npm (npm run build) on project investmentswallet: Failed to run task: 'npm run build' failed. org.apache.commons.exec.ExecuteException: Process exited with an error: -4058 (Exit value: -
4058) -> [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.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

It seems that it cant find package.json file? Why is it looking for it in the User dirtectory? it's in the client folder

Here is my pom:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.demo</groupId>
    <artifactId>investmentswallet</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>investmentswallet</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>5.3.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.9.1</version>
                <configuration>
                    <nodeVersion>v12.16.3</nodeVersion>
                </configuration>
                <executions>
                    <execution>
                        <id>install-npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm-install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>npm run build</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>process-classes</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/classes/public</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>client/dist/client</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

and here is my project structure:

enter image description here

Any idea whats going on?


Solution

  • Ok i found out that the solution to this is that in frontend-maven-plugin configuration you have to specify workingDirectory and installDirectory. So in my case the plugin definiton in pom.xml will look like this:

    <plugin>
                    <groupId>com.github.eirslett</groupId>
                    <artifactId>frontend-maven-plugin</artifactId>
                    <version>1.9.1</version>
                    <configuration>
                        <nodeVersion>v12.16.3</nodeVersion>
                        <workingDirectory>client</workingDirectory>
                        <installDirectory>target</installDirectory>
                    </configuration>
                    <executions>
                        <execution>
                            <id>install-npm</id>
                            <goals>
                                <goal>install-node-and-npm</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>npm-install</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>npm run build</id>
                            <goals>
                                <goal>npm</goal>
                            </goals>
                            <configuration>
                                <arguments>run build</arguments>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>