vaadin / flow

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

JsModule Annotation is not resolved if refering to a file inside a dependency #7752

Closed appreciated closed 3 years ago

appreciated commented 4 years ago

Description of the bug

When using Vaadin 15, the defined resouces using the @JsModule Annotation cannot be resolved at runtime, if the resource is inside an addon dependency.

I have some users having issues when using some of my addons in combination with Vaadin 15.

While everything worked under Vaadin 14 it seems no longer to work under Vaadin 15.

One user hits this issue on Tomcat, another on Spring-boot.

Minimal reproducible example with Spring Boot

Example project

Versions

Vaadin 15

mehdi-vaadin commented 4 years ago

https://github.com/vaadin/flow/issues/6069#issuecomment-595153384 may be related to this.

ugurdoksan commented 4 years ago

https://github.com/Gubancs/leaflet4vaadin/issues/2#issue-577555425

https://github.com/Juchar/color-picker-field-flow/issues/4

https://github.com/Juchar/color-picker-field/issues/7

All of them about the same bug. Waiting impatiently for this big to be solved...

syampillai commented 4 years ago

I reported a similar issue (#6069) for Vaadin 14 and it was resolved. However, with Vaadin 15, the same code is not working.

appreciated commented 4 years ago

This issue seems to be fixed by 15.0.1, is this possible? Edit: Unfortuantly not, but the production build is now running successfully.

ugurdoksan commented 4 years ago

Yes, I've tried but came accross with the same error log in Tomcat.

ugurdoksan commented 4 years ago

Waiting...

Capture

mvdberge commented 4 years ago

I might have this issues, not 100% sure. The exact issue is described in https://github.com/appreciated/apexcharts-flow/issues/51, but I also discovered the exact same errror message ("Couldn't find the definition of the element with tag 'xxxx'...") with different tags when building on another machine in a slightly different setup.

I tested various vaadin 14 versions, the latest ones were 14.1.21 and 14.2.0.alpha9. Interestingly, I was able to randomly got the application running twice out of ~40 tries, but this isn't reproducable.

Important to know that the application runs fine in development mode, I only discover this issue in production mode.

Concerning the built chain: I use maven and an embedded jetty setup, similar as described in https://github.com/mvysny/vaadin14-embedded-jetty/blob/master/pom.xml

haijian-vaadin commented 4 years ago

Update: Vaadin 15.0.3 is release today! So the hack below could be ignored.

Hi, for the Vaadin 15 users, this bug has been fixed and release in Flow 3.0.2. While Vaadin 15.0.3 is still on the way, if you are waiting impatiently, you can use Flow 3.0.2 directly in your POM file. For this you need to:

  1. Define a flow.version property
  2. Add a flow-bom dependency in the dependencyManagement
  3. Change vaadin-maven-plugin to flow-maven-plugin

I'm attaching an example pom.xml file illustrating how to use Flow 3.0.2 directly. pom.xml.zip

mvdberge commented 4 years ago

@haijian-vaadin Thanks for the update!

Will this fix be backported to Vaadin 14? I just tried vaadin 14.1.23 which still has this issue - or can I use flow 3.0.2 in vaadin 14 also?

haijian-vaadin commented 4 years ago

@mvdberge, this ticket was about Vaadin 15, we didn't know it has problems with Vaadin 14 in production mode. I just tried with the example project attached in this ticket with Vaadin 14 production mode, but I wasn't able to reproduce. Did you use the same example project or a different one? If it's a different one, can you share it here so that we can try to reproduce?

hfffranzin commented 4 years ago

@haijian-vaadin, I made the changes to the pom and it still didn't work, I'm using vaadin 15.0.3

appreciated commented 4 years ago

@hfffranzin I can confirm this issue was fixed with 15.0.3. Have you tried a clean install? What is your setup?

hfffranzin commented 4 years ago

@haijian-vaadin, yes I did clean install, however in production mode I'm having problems. when mvn package -Pprodution in my application

<properties>
    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
    <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>
    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
    <vaadin.version>15.0.3</vaadin.version>
    <flow.version>3.0.2</flow.version>
</properties>
haijian-vaadin commented 4 years ago

Hi @hfffranzin, thanks for the feedback. First of all, you don't need to specify flow 3.0.2 explicitly anymore if you are using Vaadin 15.0.3. It was a hack for people to use before 15.0.3 was released.

I have 2 questions maybe you can help to clarify:

  1. Is the non-production mode working for you? i.e. without -Pproduction
  2. How did you run your application after mvn package -Pprodution? Did you run mvn spring-boot:run -Pproduction or sth else?
hfffranzin commented 4 years ago

@haijian-vaadin ... understand...

Works normal mvn spring-boot: run

Does not work error: mvn spring-boot: run -Pproduction

java.lang.IllegalStateException: Couldn't find the definition of the element with tag 'apex-charts-wrapper' in any template file declared using '@JsModule' annotations. Check the availability of the template files in your WAR file or provide alternative implementation of the method getTemplateContent() which should return an element representing the content of the template file

haijian-vaadin commented 4 years ago

@hfffranzin, thanks for the clarification, now I can reproduce the problem.

@appreciated, it might be related to the apexcharts-addon. Haven't looked deep yet, the first impression is that:

mvdberge commented 4 years ago

With a colleague of mine, I was able to reproduce the same problem with the vaadin-app-layout plugin which works fine in development mode, but doesn't work in production mode.

Error: java.lang.IllegalStateException: Couldn't find the definition of the element with tag 'app-layout-left-responsive' in any template file declared using '@JsModule' annotations. Check the availability of the template files in your WAR file or provide alternative implementation of the method getTemplateContent() which should return an element representing the content of the template file

haijian-vaadin commented 4 years ago

Thank you @mvdberge for the feedback, we started investigating on this.

mvdberge commented 4 years ago

I just found out that the bug with vaadin-app-layout seems to be resolved, see https://github.com/appreciated/vaadin-app-layout/issues/303

But there is not yet a new release, so I didn't try the fix

manolo commented 4 years ago

Reopened until fixed the prod build

haijian-vaadin commented 4 years ago

addon-vaadin-15-test.zip

Attaching a project to reproduce the problem. In the project, it uses both the card and the apexcharts addon.

In the MainView class, if you don't reference to apexcharts, then it works.

appreciated commented 4 years ago

I have users that report similar issues under Vaadin 14.2. I have unfortunatly currently no time to investigate this.

manolo commented 4 years ago

Fixed with https://github.com/vaadin/flow/pull/8056

haijian-vaadin commented 4 years ago

Hi @appreciated @mvdberge @hfffranzin The fix is now in 15.0.5, you can give it a try and let us know if it works for you.

hfffranzin commented 4 years ago

@haijian-vaadin Good morning, I updated the vaadin and it worked, both in development and production thank you so much

mvdberge commented 4 years ago

@haijian-vaadin Will the fix be backported to Vaadin 14 LTS?

caalador commented 4 years ago

The fix is also in 14.2. 14.1. didn't have the issue.

mvdberge commented 4 years ago

I still have the issue in 14.2.0.beta1, but I also had the issue in any 14.1 versions I tried (see my comments above) I could try Vaadin 15, but it would still be great to see the fix of my problem in an LTS version

caalador commented 4 years ago

Could you please create a ticket for the problem with 14.1 and 14.2 with a minimal sample project and exact steps to reproduce.

damian-burda commented 4 years ago

Hi, I have exactly the same problem with 14.1.28, spring boot and using @appreciated app-layout plugin.

Couldn't find the definition of the element with tag 'app-layout-left-responsive-hybrid' in any template file declared using '@JsModule' annotations. Check the availability of the template files in your WAR file or provide alternative implementation of the method getTemplateContent() which should return an element representing the content of the template file

damian-burda commented 4 years ago

I tried with 14.2.0.rc1 and got the same exception.

caalador commented 4 years ago

Please open a new ticket for the issue with reproducable steps. A sample project would help.

damian-burda commented 4 years ago

I'm trying, but in a fresh project I can't reproduce it. What I can tell is, that in my original project generated-flow-imports.js has only 3 imports, same for package.json in has only 3 dependencies. I'm still trying to figure it out. I'm using gradle for build.

caalador commented 4 years ago

Custom gradle or the vaadin-gradle-plugin 0.6.0?

markhm commented 4 years ago

Hi @pogodna,

Please try a trick as you see here in line 31-42.

I've just tried to quickly reproduce why this was necessary for me, but without success. I am using 15.0.6 atm and I don't have more time to look into this. Hope it helps though.

damian-burda commented 4 years ago

Custom gradle or the vaadin-gradle-plugin 0.6.0?

vaadin-gradle-plugin 0.6.0 I could narrow it down yesterday to the point where DevModeServletContextListener does not find all needed classes, that should be scanned. It happens when I build with gradlew clean vaadinClean vaadinPrepareFrontend build bootRun

Only my classes are found and none from dependencies. When I run it in Intellij in debug, then it finds everything

kobazzo commented 4 years ago

I have the same problem with Vaadin 15.0.6 only in production mode. Someone have the solution?

haijian-vaadin commented 4 years ago

@kobazzo Have you tried to clean all the generated files: node_modules, target, package.json, package-lock.json, webpack.config.js, webpack.generated.js

If it doesn't help, could you share with us a project that we can use to reproduce the problem?

kobazzo commented 4 years ago

@kobazzo Have you tried to clean all the generated files: node_modules, target, package.json, package-lock.json, webpack.config.js, webpack.generated.js

If it doesn't help, could you share with us a project that we can use to reproduce the problem?

@haijian-vaadin Thank for the answer. What do you mean with "clean all the generated files" ? How can i do this?

This is the exact exception:

java.lang.IllegalStateException: Couldn't find the definition of the element with tag 'color-picker-field' in any template file declared using '@JsModule' annotations. Check the availability of the template files in your WAR file or provide alternative implementation of the method getTemplateContent() which should return an element representing the content of the template file

haijian-vaadin commented 4 years ago

@kobazzo sorry about the wording, just meant that delete all those files/folders (node_modules, target, package.json, package-lock.json, webpack.config.js, webpack.generated.js).

But never mind, I was able to reproduce the problem with the color picker field addon, as indicated in the exception.

haijian-vaadin commented 4 years ago

Hi @kobazzo, since the issue you reported is a bit different from the original issue in this ticket, I made a new one https://github.com/vaadin/flow/issues/8493, you can follow the progress there.

kobazzo commented 4 years ago

Hi @kobazzo, since the issue you reported is a bit different from the original issue in this ticket, I made a new one #8493, you can follow the progress there.

@haijian-vaadin Thank you.

stefanuebe commented 3 years ago

This issue seems to still exists somehow, we have that now in a V20 project. I'll try to create a sample project with the reproducable issue.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sample.app.SampleCardView': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [sample.app.SampleCardView]: Constructor threw exception; nested exception is java.lang.IllegalStateException: Couldn't find the definition of the element with tag 'content-card' in any template file declared using '@JsModule' annotations. Check the availability of the template files in your WAR file or provide alternative implementation of the method getTemplateContent() which should return an element representing the content of the template file
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1316) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:524) ~[spring-beans-5.3.8.jar:5.3.8]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:314) ~[spring-beans-5.3.8.jar:5.3.8]
    at com.vaadin.flow.spring.SpringInstantiator.getOrCreate(SpringInstantiator.java:117) ~[vaadin-spring-17.0.1.jar:na]
    at com.vaadin.flow.di.Instantiator.createRouteTarget(Instantiator.java:193) ~[flow-server-7.0.2.jar:7.0.2]
stefanuebe commented 3 years ago

My steps to reproduce:

github-vaadin-flow-7752-example.zip

stefanuebe commented 3 years ago

Can also be reproduced with our default V20 starter, simply add for instance

<dependency>
    <groupId>com.github.appreciated</groupId>
    <artifactId>card</artifactId>
    <version>2.0.0</version>
</dependency>

then clean install and run as a Spring Boot Java App.

haijian-vaadin commented 3 years ago

It works with mvn and mvn -Pproduction, the reported problem occurs when trying to run the Application class inside IDE.

pleku commented 3 years ago

I'm closing this in favor of a new issue #11325 as it has been a long time since the original issue, and while I look at the error messages, I'm not certain that either of the two fixes done for this earlier are related.