vaadin / flow

Vaadin Flow is a Java framework binding Vaadin web components to Java. This is part of Vaadin 10+.
Apache License 2.0
616 stars 167 forks source link

Missing js modules at start after building fat jar with profile production #6596

Closed mmirwaldt closed 4 years ago

mmirwaldt commented 5 years ago

I can run my vaadin application from IntelliJ IDE but not from console as fat jar. What I use:

I get the following error:

2019-10-01 21:47:17.149  INFO 41556 --- [           main] dev-updater                              :

  Failed to find the following imports in the `node_modules` tree:
      - @vaadin/flow-frontend/contextMenuConnector-es6.js
      - @vaadin/flow-frontend/gridConnector.js
      - @vaadin/flow-frontend/contextMenuConnector.js
      - @vaadin/flow-frontend/flow-component-renderer.js
      - @vaadin/flow-frontend/gridConnector-es6.js
      - @vaadin/flow-frontend/vaadin-grid-flow-selection-column.js
  If the build fails, check that npm packages are installed.

My pom.xml (the *** in artifact id in the parent tag are a real name. I must hide it here ;-) :

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>net.mirwaldt.***</artifactId>
        <groupId>net.mirwaldt</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>webapp</artifactId>

    <properties>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

        <vaadin.version>14.0.7</vaadin.version>

        <drivers.dir>${project.basedir}/drivers</drivers.dir>
        <drivers.downloader.phase>pre-integration-test</drivers.downloader.phase>
    </properties>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2/</url>
            <snapshots><enabled>false</enabled></snapshots>
        </pluginRepository>
    </pluginRepositories>

    <repositories>
        <repository>
            <id>central</id>
            <url>https://repo1.maven.org/maven2/</url>
            <snapshots><enabled>false</enabled></snapshots>
        </repository>
        <!-- Repository used by many Vaadin add-ons -->
        <repository>
            <id>Vaadin Directory</id>
            <url>https://maven.vaadin.com/vaadin-addons</url>
            <snapshots><enabled>false</enabled></snapshots>
        </repository>
    </repositories>

    <!-- https://www.baeldung.com/spring-boot-dependency-management-custom-parent -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.1.7.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>

        <dependency>
            <groupId>com.vaadin</groupId>
            <!-- Replace artifactId with vaadin-core to use only free components -->
            <artifactId>vaadin</artifactId>
            <exclusions>
                <!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
                <exclusion>
                    <groupId>com.vaadin.webjar</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.insites</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymer</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.polymerelements</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.vaadin</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.webjars.bowergithub.webcomponents</groupId>
                    <artifactId>*</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
            <exclusions>
                <!-- Excluding so that webjars are not included. -->
                <exclusion><groupId>com.vaadin</groupId>
                    <artifactId>vaadin-core</artifactId></exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-testbench</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <defaultGoal>spring-boot:run</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.1.7.RELEASE</version>

                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!--
                Take care of synchronizing java dependencies and imports in
                package.json and main.js files.
                It also creates webpack.config.js if not exists yet.
            -->
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>build-frontend</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <!-- Production mode is activated using -Pproduction -->
            <id>production</id>
            <properties>
                <vaadin.productionMode>true</vaadin.productionMode>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>com.vaadin</groupId>
                    <artifactId>flow-server-production-mode</artifactId>
                </dependency>
            </dependencies>

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                        <configuration>
                            <jvmArguments>-Dvaadin.productionMode</jvmArguments>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>com.vaadin</groupId>
                        <artifactId>vaadin-maven-plugin</artifactId>
                        <executions>
                            <execution>
                                <goals>
                                    <goal>build-frontend</goal>
                                </goals>
                                <phase>compile</phase>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

I see that the folder npm_modules/@vaadin/flow-frontend is empty but the missing js-files are in the fatjar under META-INF/resources/frontend:

  - contextMenuConnector-es6.js
  - gridConnector.js
  - contextMenuConnector.js
  - flow-component-renderer.js
  - gridConnector-es6.js
  - vaadin-grid-flow-selection-column.js

Removing

didn't help. It always runs in the same error and cannot build the frontend. What''s going wrong? How can I fix it? Is there a workaround?

mmirwaldt commented 5 years ago

I discovered that target/frontend/generated-flow-imports.js references those missing js modules under npm_modules/@vaadin/flow-frontend/ :

...
import '@vaadin/flow-frontend/flow-component-renderer.js';
import '@vaadin/flow-frontend/gridConnector-es6.js';
import '@vaadin/flow-frontend/vaadin-grid-flow-selection-column.js';
import '@vaadin/flow-frontend/contextMenuConnector-es6.js';
...
import '@vaadin/flow-frontend/gridConnector.js';
import '@vaadin/flow-frontend/contextMenuConnector.js';

Shouldn't it be:

...
import 'frontend://flow-component-renderer.js';
import 'frontend://gridConnector-es6.js';
import 'frontend://vaadin-grid-flow-selection-column.js';
import 'frontend://contextMenuConnector-es6.js';
...
import 'frontend://gridConnector.js';
import 'frontend://contextMenuConnector.js';

Then it would reference to the frontend folder under META-INF/resources/frontend according to this post

mmirwaldt commented 5 years ago

I discovered that #5632 tried to introduce it but broke it.

mmirwaldt commented 5 years ago

I found a workaround: I copied all files from META-INF/resources/frontend to npm_modules/@vaadin/flow-frontend/. That works.

Changing target/frontend/generated-flow-imports.js does not work because it is overwritten with every restart.

mmirwaldt commented 5 years ago

I opened a discussion in the forum https://vaadin.com/forum/thread/17871763 . I am not sure whether this issue is a ticket or a discussion in the forum.

joheriks commented 5 years ago

@mmirwaldt Before packaging the fat jar, did you run vaadin:prepare-frontend (this goal is missing from the pom.xml but I do not know what is in the parent)? Also, how do you run the fat jar?

I was able to start the application without npm errors with the pom.xml above as follows: mvn -Pproduction vaadin:prepare-frontend package java -jar target/webapp-0.0.1-SNAPSHOT.jar

mmirwaldt commented 5 years ago

@joheriks The parent is just a pom listing the modules my project has. Nothing special. My vaadin webapplication is a separate module in the profile webapp.

Here is it: `<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

4.0.0
<groupId>net.mirwaldt</groupId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
<artifactId>net.mirwaldt.***</artifactId>

<name>***</name>
<description>***</description>
<url>***</url>

<modules>
    <module>core</module>
    <module>core-demos</module>
    <module>object</module>
    <module>object-demos</module>
    <module>data</module>
</modules>

<profiles>
    <profile>
        <id>webapp-demo
        </id>
        <modules>
            <module>webapp</module>
        </modules>
    </profile>
</profiles>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19.1</version>
            <dependencies>
                <dependency>
                    <groupId>org.junit.platform</groupId>
                    <artifactId>junit-platform-surefire-provider</artifactId>
                    <version>1.0.1</version>
                </dependency>
                <dependency>
                    <groupId>org.junit.jupiter</groupId>
                    <artifactId>junit-jupiter-engine</artifactId>
                    <version>5.0.1</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.2</version>
            <executions>
                <execution>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <phase>test</phase>
                    <goals>
                        <goal>report</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-api</artifactId>
        <version>5.0.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.0.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-params</artifactId>
        <version>5.0.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-launcher</artifactId>
        <version>1.0.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-runner</artifactId>
        <version>1.0.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>3.0.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

`

I run the fat jar as a service on my centos 7 server without maven.

I changed the goal to "prepare-frontend" in the vaadin-maven-plugin and will try it out soon. I will answer here again if it worked.

polishcode commented 4 years ago

@mmirwaldt did it work for you? I am facing the same problem. I already tried mvn -Pproduction vaadin:prepare-frontend package suggested by @joheriks , but running the app fails like before.

joheriks commented 4 years ago

@mmirwaldt Could you run the fat jar or do you still experience the same issue efter running
@polishcode Can you provide a minimal self-contained example that exposes the issue?

mmirwaldt commented 4 years ago

I have tried out and it does not work. I get "Failed to find the bundle manifest file 'frontend://vaadin-flow-bundle-manifest.json' in the servlet context for 'ES6' browsers. If you are running a dev-mode servlet container in maven e.g. jetty:run change it to jetty:run-exploded. If you are not compiling frontend resources, include the 'vaadin-maven-plugin' in your build script. Otherwise, you can skip this error either by disabling production mode, or by setting the servlet parameter 'original.frontend.resources=true'." Even setting original.frontend.resources=true in application.properties or in system properties does not work. :-(

mmirwaldt commented 4 years ago

I could solve that problem by adding the system property vaadin.original.frontend.resources=true . I don't know why but setting both goals

prepare-frontend
                        <goal>build-frontend</goal>

seems to solve the problem.

denis-anisimov commented 4 years ago

vaadin-flow-bundle-manifest.json file and vaadin.original.frontend.resources make sense and do something only in compatibility mode. So apparently you are running the app in compatibility mode.

The original reports was about NPM mode.

Also the original report is about dev mode since you should not have any dev-updater errors in production mode.

Just ti clarify: to be able to run you app in production mode you should:

denis-anisimov commented 4 years ago

Also please note that there is https://github.com/vaadin/flow/issues/6657. Which is about running fat jar in dev mode without need to specify production mode property explicitly.

mehdi-vaadin commented 4 years ago

@mmirwaldt #6657 and some other issues related to fat jar have been recently fixed. Would you please try Vaadin 14.0.13 and see if your problem is resolved?

pleku commented 4 years ago

Closing the issue as it probably has been fixed, but there has not been a response from the author in a reasonable time. If the issue is still valid, please reopen with instructions on how to reproduce.