There is one common issue occurring when we upgrade vaadin 14 to 24
We have multiple custom web components, and one of them is JTJsonTreeView in our multi-module Maven project that is not loading its JavaScript module. The component is defined in a
vaadin-base module and used in a webapp module, but the JavaScript file is never loaded by the browser.
Environment
- Vaadin Version: 24.7.3
- Spring Boot Version: 3.5.0
- Java Version: 24
- Build Tool: Maven
- Project Structure: Multi-module Maven project
Project Structure
protocols/
├── vaadin-base/ (library module with shared components)
│ └── src/main/java/…/JTJsonTreeView.java
│ └── src/main/resources/META-INF/resources/frontend/json-tree-view/jt-json-tree-view.js
└── webapp/ (main application module)
└── Uses JTJsonTreeView component
Component Definition (vaadin-base module)
package com.justransform.app.vaadin.components.json.treeview;
@Tag("jt-json-tree-view")
@NpmPackage(value = "jsoneditor", version = "9.5.7")
@NpmPackage(value = "diff", version = "5.0.0")
@NpmPackage(value = "jsondiffpatch", version = "0.4.1")
@JsModule("./json-tree-view/jt-json-tree-view.js")
public class JTJsonTreeView extends Component implements HasSize {
// Component implementation
}
Problem
- The component is instantiated correctly in Java (constructor is called)
- The component is attached to the DOM (visible as element)
- However, the JavaScript module jt-json-tree-view.js is never loaded
- Browser console shows:
- No network request for the JS file
- customElements.get(‘jt-json-tree-view’) returns undefined
- Component methods (loadContent, etc.) are undefined on the element
What We’ve Tried
- Different file locations:
- vaadin-base/src/main/resources/META-INF/resources/frontend/json-tree-view/jt-json-tree-view.js
- vaadin-base/frontend/json-tree-view/jt-json-tree-view.js
- webapp/frontend/json-tree-view/jt-json-tree-view.js - Different JsModule paths:
- JsModule(“./json-tree-view/jt-json-tree-view.js”)
- JsModule(“json-tree-view/jt-json-tree-view.js”)
- JsModule(“/json-tree-view/jt-json-tree-view.js”) - Build commands:
- mvn clean install
- mvn vaadin:prepare-frontend
- mvn vaadin:build-frontend
Expected Behavior
When the JTJsonTreeView component is used in the webapp module, Vaadin should:
- Detect the JsModule annotation
- Include the JavaScript file in the bundle
- Load and execute the JavaScript module
- Register the custom element
Actual Behavior
- The JavaScript file is never requested by the browser
- No compilation errors during build
- The component appears in DOM but without any JavaScript functionality
- Manual dynamic imports also fail with 404 errors
Additional Context
During application startup, we see Lit-related errors for other Vaadin components:
ERROR: No matching export in “node_modules/lit/index.js” for import “adoptStyles”
However, our component doesn’t use Lit - it’s either using LitElement with proper imports or vanilla JavaScript with native Web Components API.
Questions
- What is the correct way to structure JavaScript modules for components in a separate Maven module (vaadin-base) that are used in another module (webapp)?
- Should the JavaScript files be placed in a specific directory for Vaadin 24 to detect them?
- Is there additional configuration needed for multi-module projects?
- Why might the JsModule annotation not trigger the loading of the JavaScript file?
Reproduction Steps
- Create a multi-module Maven project with vaadin-base and webapp modules
- Create a custom component in vaadin-base with @JsModule annotation
- Use the component in webapp module
- Observe that the JavaScript file is never loaded in the browser
Any guidance on properly configuring custom web components in a multi-module Vaadin 24 project would be greatly appreciated.