Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vaadin 23.2 Vite not working with Liferay portlets #240

Open
krissvaa opened this issue Nov 22, 2022 · 4 comments
Open

Vaadin 23.2 Vite not working with Liferay portlets #240

krissvaa opened this issue Nov 22, 2022 · 4 comments

Comments

@krissvaa
Copy link

krissvaa commented Nov 22, 2022

Vaadin 23.2 using default settings (using Vite) builds but when portlets are deployed on Liferay fails with missing stats.json.

  • Versions:

    • Vaadin Portlet version: 2.0.0
    • Flow version: 23.2.8
    • Portal (Liferay) version: 7.3.6
    • Java version: 11
    • OS version: WIndows
  • Server logs:

   2022-11-22 07:52:42.037 WARN  [http-nio-8080-exec-7][code_jsp:161] {code="404", msg="ProxyServlet: /o/vaadin-portlet-static/VAADIN/config/stats.json", uri=/o/vaadin-portlet-static/VAADIN/config/stats.json}
2022-11-22 07:52:42.063 ERROR [http-nio-8080-exec-2][FrontendUtils:500] Failed to retrieve stats.json from the url http://localhost:8080/o/vaadin-portlet-static/VAADIN/config/stats.json.
java.io.FileNotFoundException: http://localhost:8080/o/vaadin-portlet-static/VAADIN/config/stats.json
   at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
   at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
   at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1989)
   at java.base/sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1984)
   at java.base/java.security.AccessController.doPrivileged(Native Method)
   at java.base/sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1983)
   at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1541)
   at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1525)
   at com.vaadin.flow.server.frontend.FrontendUtils.getStatsFromExternalUrl(FrontendUtils.java:498)
   at com.vaadin.flow.server.frontend.FrontendUtils.getStatsAssetsByChunkName(FrontendUtils.java:590)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.appendNpmBundle(BootstrapHandler.java:972)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupFrameworkLibraries(BootstrapHandler.java:954)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupDocumentHead(BootstrapHandler.java:833)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.getBootstrapPage(BootstrapHandler.java:600)
   at com.vaadin.flow.server.communication.WebComponentBootstrapHandler.synchronizedHandleRequest(WebComponentBootstrapHandler.java:217)
   at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
   at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1578)
   at com.vaadin.flow.portal.VaadinPortlet.handleRequest(VaadinPortlet.java:403)
   at com.vaadin.flow.portal.VaadinPortlet.serveResource(VaadinPortlet.java:342)
   at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:146)
   at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:88)
   at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:140)
   at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:78)
   at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.AsyncAttributeAdapterServlet.service(AsyncAttributeAdapterServlet.java:85)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletExceptionAdapter.service(ServletExceptionAdapter.java:76)
   at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
   at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
   at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:124)
   at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:104)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.FilterExceptionAdapter.doFilter(FilterExceptionAdapter.java:46)
   at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(FilterRegistration.java:121)
   at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:45)
   at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:70)
   at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
   at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.forward(RequestDispatcherAdaptor.java:40)
   at com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:565)
   at com.liferay.portlet.internal.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:680)
   at com.liferay.portlet.internal.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:494)
   at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.serveResource(MonitoringInvokerPortlet.java:292)
   at com.liferay.portlet.internal.PortletContainerImpl._serveResource(PortletContainerImpl.java:1077)
   at com.liferay.portlet.internal.PortletContainerImpl.lambda$serveResource$4(PortletContainerImpl.java:267)
   at com.liferay.portlet.internal.PortletContainerImpl._preserveGroupIds(PortletContainerImpl.java:425)
   ...
Caused by: java.io.FileNotFoundException: http://localhost:8080/o/vaadin-portlet-static/VAADIN/config/stats.json
   at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1935)
   at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1525)
   at java.base/sun.net.www.protocol.http.HttpURLConnection.getHeaderField(HttpURLConnection.java:3129)
   at com.vaadin.flow.server.frontend.FrontendUtils.getStatsFromExternalUrl(FrontendUtils.java:482)
   ... 168 more
2022-11-22 07:52:42.067 ERROR [http-nio-8080-exec-2][DefaultPortletErrorHandler:29] com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupFrameworkLibraries(BootstrapHandler.java:956)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupDocumentHead(BootstrapHandler.java:833)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.getBootstrapPage(BootstrapHandler.java:600)
   at com.vaadin.flow.server.communication.WebComponentBootstrapHandler.synchronizedHandleRequest(WebComponentBootstrapHandler.java:217)
   at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
   at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1578)
   at com.vaadin.flow.portal.VaadinPortlet.handleRequest(VaadinPortlet.java:403)
   at com.vaadin.flow.portal.VaadinPortlet.serveResource(VaadinPortlet.java:342)
   at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:146)
   at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:88)
   at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:140)
   at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:78)
   at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.AsyncAttributeAdapterServlet.service(AsyncAttributeAdapterServlet.java:85)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletExceptionAdapter.service(ServletExceptionAdapter.java:76)
   at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
   at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
   at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:124)
   at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:104)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.FilterExceptionAdapter.doFilter(FilterExceptionAdapter.java:46)
   at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(FilterRegistration.java:121)
   at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:45)
   at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:70)
   at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
   at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.forward(RequestDispatcherAdaptor.java:40)
   at com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:565)
   at com.liferay.portlet.internal.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:680)
   at com.liferay.portlet.internal.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:494)
   at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.serveResource(MonitoringInvokerPortlet.java:292)
   at com.liferay.portlet.internal.PortletContainerImpl._serveResource(PortletContainerImpl.java:1077)
   at com.liferay.portlet.internal.PortletContainerImpl.lambda$serveResource$4(PortletContainerImpl.java:267)
   at com.liferay.portlet.internal.PortletContainerImpl._preserveGroupIds(PortletContainerImpl.java:425)
   at com.liferay.portlet.internal.PortletContainerImpl.serveResource(PortletContainerImpl.java:260)
   at com.liferay.portlet.SecurityPortletContainerWrapper.serveResource(SecurityPortletContainerWrapper.java:209)
   at com.liferay.portlet.RestrictPortletContainerWrapper.serveResource(RestrictPortletContainerWrapper.java:150)
   at com.liferay.portal.kernel.portlet.PortletContainerUtil.serveResource(PortletContainerUtil.java:232)
   at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:409)
   at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:173)
   at com.liferay.portal.struts.PortalRequestProcessor._process(PortalRequestProcessor.java:408)
   at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:154)
   at com.liferay.portal.internal.servlet.MainServlet.doGet(MainServlet.java:206)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:626)
   at com.liferay.portal.internal.servlet.MainServlet.service(MainServlet.java:631)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   ....
Caused by: java.io.IOException: The stats file from webpack (stats.json) was not found._The application is running in production mode.Verify that build-frontend task has executed successfully and that stats.json is on the classpath.Or switch application to development mode. [Sanitized]
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.appendNpmBundle(BootstrapHandler.java:997)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupFrameworkLibraries(BootstrapHandler.java:954)
   ... 165 more
2022-11-22 07:52:42.071 ERROR [http-nio-8080-exec-2][PortletServlet:119] javax.portlet.PortletException: com.vaadin.flow.server.ServiceException: com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
javax.portlet.PortletException: com.vaadin.flow.server.ServiceException: com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
   at com.vaadin.flow.portal.VaadinPortlet.handleRequest(VaadinPortlet.java:406)
   at com.vaadin.flow.portal.VaadinPortlet.serveResource(VaadinPortlet.java:342)
   at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:146)
   at com.liferay.portlet.ScriptDataPortletFilter.doFilter(ScriptDataPortletFilter.java:88)
   at com.liferay.portlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:140)
   at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:78)
   at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:115)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.AsyncAttributeAdapterServlet.service(AsyncAttributeAdapterServlet.java:85)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.ServletExceptionAdapter.service(ServletExceptionAdapter.java:76)
   at org.eclipse.equinox.http.servlet.internal.registration.EndpointRegistration.service(EndpointRegistration.java:153)
   at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:50)
   at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilterChain.doFilter(InvokerFilterChain.java:124)
   at com.liferay.portal.kernel.servlet.filters.invoker.InvokerFilter.doFilter(InvokerFilter.java:104)
   at com.liferay.portal.osgi.web.wab.extender.internal.adapter.FilterExceptionAdapter.doFilter(FilterExceptionAdapter.java:46)
   at org.eclipse.equinox.http.servlet.internal.registration.FilterRegistration.doFilter(FilterRegistration.java:121)
   at org.eclipse.equinox.http.servlet.internal.servlet.FilterChainImpl.doFilter(FilterChainImpl.java:45)
   at org.eclipse.equinox.http.servlet.internal.servlet.ResponseStateHandler.processRequest(ResponseStateHandler.java:70)
   at org.eclipse.equinox.http.servlet.internal.context.DispatchTargets.doDispatch(DispatchTargets.java:120)
   at org.eclipse.equinox.http.servlet.internal.servlet.RequestDispatcherAdaptor.forward(RequestDispatcherAdaptor.java:40)
   at com.liferay.portlet.internal.InvokerPortletImpl.invoke(InvokerPortletImpl.java:565)
   at com.liferay.portlet.internal.InvokerPortletImpl.invokeResource(InvokerPortletImpl.java:680)
   at com.liferay.portlet.internal.InvokerPortletImpl.serveResource(InvokerPortletImpl.java:494)
   at com.liferay.portal.monitoring.internal.portlet.MonitoringInvokerPortlet.serveResource(MonitoringInvokerPortlet.java:292)
   at com.liferay.portlet.internal.PortletContainerImpl._serveResource(PortletContainerImpl.java:1077)
   at com.liferay.portlet.internal.PortletContainerImpl.lambda$serveResource$4(PortletContainerImpl.java:267)
   at com.liferay.portlet.internal.PortletContainerImpl._preserveGroupIds(PortletContainerImpl.java:425)
   at com.liferay.portlet.internal.PortletContainerImpl.serveResource(PortletContainerImpl.java:260)
       ...
Caused by: com.vaadin.flow.server.ServiceException: com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
   at com.vaadin.flow.server.VaadinService.handleExceptionDuringRequest(VaadinService.java:1627)
   at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1590)
   at com.vaadin.flow.portal.VaadinPortlet.handleRequest(VaadinPortlet.java:403)
   ... 159 more
Caused by: com.vaadin.flow.server.BootstrapException: Unable to read webpack stats file.
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupFrameworkLibraries(BootstrapHandler.java:956)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupDocumentHead(BootstrapHandler.java:833)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.getBootstrapPage(BootstrapHandler.java:600)
   at com.vaadin.flow.server.communication.WebComponentBootstrapHandler.synchronizedHandleRequest(WebComponentBootstrapHandler.java:217)
   at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
   at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1578)
   ... 160 more
Caused by: java.io.IOException: The stats file from webpack (stats.json) was not found._The application is running in production mode.Verify that build-frontend task has executed successfully and that stats.json is on the classpath.Or switch application to development mode. [Sanitized]
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.appendNpmBundle(BootstrapHandler.java:997)
   at com.vaadin.flow.server.BootstrapHandler$BootstrapPageBuilder.setupFrameworkLibraries(BootstrapHandler.java:954)
   ... 165 more
   ```
@krissvaa krissvaa added the bug Something isn't working label Nov 22, 2022
@mshabarov
Copy link
Contributor

For Vite build tool we can generate a basic stats.json in Flow, so Portlet wouldn't throw an error.

@krissvaa
Copy link
Author

krissvaa commented Dec 9, 2022

Seems there is another issue, that web-component.html is missing when built with VITE (or just in wrong path, could be problem with not searching for it under /o/static-vaadin-portlet)

For now there is a workaround - but it is not a pretty one as portlets will include static files as well:
For example inside https://github.com/vaadin/addressbook-portlet/blob/v23/addressbook-form/pom.xml
Using this configuration

        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>
            <plugin>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-maven-plugin</artifactId>
                <version>${vaadin.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-frontend</goal>
                            <goal>build-frontend</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.3</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>war</goal>
                        </goals>
                        <configuration>
                            <primaryArtifact>true</primaryArtifact>
                            <packagingExcludes>WEB-INF/classes/META-INF/VAADIN/build/**,VAADIN/</packagingExcludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

@mcollovati
Copy link
Contributor

The problem with web-component.html is that at runtime it is read from class path at the position META-INF/VAADIN/webapp/we-component.html, and this file is generated by vaadin-maven-plugin.
In a multimodule project with a static bundle portlet, the file is present only on this one, and is not accessible by other modules as classpath resource.
We should investigate if a custom ResourceProvider implementation may work in this situation

@mcollovati
Copy link
Contributor

mcollovati commented Dec 9, 2022

For multimodule projects, there's a workaround, but it requires a bit of configuration.
Basically, the idea is to add a companion module (as an additional pom file in the same folder) for every portlet that builds the classes jar used by the static bundle module.
The static bundle module generates the war and an addition JAR artifact that contains only META-INF/VAADIN/webapp/ files.
This jar is then added as a dependency to the portlet war POM.

An example can be found in the addressbook-portlet issues/portlet-243 branch

mcollovati added a commit to vaadin/base-starter-flow-portlet that referenced this issue Dec 13, 2022
Update maven war plugin configuration to pack static files in the expected
position.
Webpack is used because currently there's an issue running Vite with Portlet
(see vaadin/portlet#240).
mcollovati added a commit to vaadin/addressbook-portlet that referenced this issue Dec 13, 2022
Currently, Vaadin portlets only work with Webpack.
References vaadin/portlet#240
mcollovati added a commit to vaadin/addressbook-portlet that referenced this issue Dec 13, 2022
Update maven configuration to support Vaadin 23.2+
Enables Webpack, because of an issue with Vite (vaadin/portlet#240).

References vaadin/portlet#243
mcollovati added a commit to vaadin/base-starter-flow-portlet that referenced this issue Dec 13, 2022
Update maven war plugin configuration to pack static files in the expected
position.
Webpack is used because currently there's an issue running Vite with Portlet
(see vaadin/portlet#240).
mshabarov pushed a commit to vaadin/addressbook-portlet that referenced this issue Dec 13, 2022
Update maven configuration to support Vaadin 23.2+
Enables Webpack, because of an issue with Vite (vaadin/portlet#240).

References vaadin/portlet#243
mshabarov pushed a commit to vaadin/base-starter-flow-portlet that referenced this issue Dec 14, 2022
Update maven war plugin configuration to pack static files in the expected
position.
Webpack is used because currently there's an issue running Vite with Portlet
(see vaadin/portlet#240).
@mshabarov mshabarov moved this to 🔖 Normal Priority (P2) in Vaadin Flow bugs & maintenance (Vaadin 10+) Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Normal Priority (P2)
Development

No branches or pull requests

4 participants