Skip to content

feat: report JavaScript definition imports that can not be resolved - #27491

Merged
mcollovati merged 20 commits into
mainfrom
issue-27424-unresolved-js-definition-imports
Nov 30, 2026
Merged

mcollovati merged 20 commits into
mainfrom
issue-27424-unresolved-js-definition-imports

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #27424
Part of #25814

build failure · flow-build-tools, flow-server, vaadin-dev-server · applications with a @JsDefinitionImport of a ./ file the build can not find

A @JsDefinitionImport of a missing ./ file used to stop the production build, and in development mode every page showed that the dev server failed to start. The messages did not name the Java interface. Now only the methods that import the missing file are left out. The build log says which interface, methods and module, and why. Calling such a method throws on the server, every time, naming the module. The rest of the application works.

Risks:

  • ⚠️ Only ./ files are checked. An npm package the project does not declare is kept, as it may be installed as a dependency of another package or be a Vite alias, which can not be told before npm install. The build logs it at DEBUG level, naming the interface, methods and package. If the package is really missing, Vite stops the build as before, and running again with -X shows that line.

  • ✅ No public API change outside internal classes, no serialization, threading or memory impact. A production server reads the list once from the stats. A development server reads it again only when the file changes, and only for calls of methods whose interface has @JsDefinitionImport.

  • Added a check before Vite runs: a ./ path is looked for in the frontend folder with the extensions and index files Vite tries, and in META-INF/frontend / META-INF/resources/frontend of the class path as named.

  • The functions of such methods are left out of the generated file, in the build and when the frontend dev server picks up a hotswapped definition. Their ids are recorded with the module in vaadin-js-definition-ids.json and in the bundle stats (jsDefinitionUnresolvedImports), keyed by function id, so the production bundle names no Java class.

  • Without the frontend dev server, the list stays as the bundle was built. A hotswapped definition that now imports a missing file is reported as not applied, with the advice to restart, and the module is logged.

  • The Javadoc of @JsDefinitionImport, Element.executeJs(Class) and Page.executeJs(Class) says that such a method throws at each call while the rest keeps working.

  • What is left out of the bundle is logged as one ERROR entry with one item per definition, sorted by class name. This covers definitions whose module can not be found (naming the methods and module) and definitions that declare something wrong. @JsDefinitionImport on a class gets a second entry listing the classes. Nothing is logged when there is nothing to list.

  • These entries are logged only when the file is written, and once on hotswap. Before, the bundle check logged the older messages a second time, because it renders the file too.

  • JsDefinitionProxy throws IllegalStateException when such a method is called. The check runs per call, so an inherited method with imports that are found still works. It looks at the list only when the interface declaring the method has imports, cached per interface. Stats without the entry fall back to the check from feat: log error for JavaScript definitions missing from bundle #27078.

  • The bundle is rebuilt when the list of left-out functions differs from the stats, or when a missing module appears. Left-out functions do not count as missing, so an unchanged project does not rebuild.

  • The check from feat: log error for JavaScript definitions missing from bundle #27078 no longer advises @Uses for left-out functions.

  • Existing tests that imported ./ files they never created now create them, as such imports are left out now.

Working on behalf of @mcollovati

A @JsDefinitionImport module that the build can not find made Vite
stop the production build, and in development mode every page showed
that the dev server failed to start, without naming the Java interface.

The build now checks each module before Vite runs: a ./ path against
the frontend folder and the frontend files of jars, as Vite looks for
it, and an npm package against the dependencies the project declares.
The functions that import a module that is not found are left out of
the generated file, in the build and when a definition is hotswapped,
and the build log says why. Their identifiers are listed with the
module in vaadin-js-definition-ids.json and the bundle stats, and a
call of such a method throws on the server, every time, naming the
module. Inherited methods with imports that are found keep working.

The bundle is rebuilt only when the list of left-out functions
changes or a missing module appears, and the bundle check of the
production server no longer advises @uses for these functions.

Existing tests that imported files they never created now create
them, as such imports are left out now.

Fixes #27424
A frontend file of a jar is imported from where the build copies it
only when the path names it as it is, so a jar file without its
extension is reported as not found rather than failing in Vite. Subpath
imports starting with # are taken to resolve.

Without the frontend dev server the browser keeps the dev bundle, so a
hotswap no longer changes the list of left-out functions the server
reads.

Tests that import an npm package now declare it, as an undeclared
package is left out.
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Type of change

  • Feature

How to test

  1. Use the reproducer of the issue: https://github.com/mcollovati/skeleton-starter-flow-spring/tree/repro/js-definition-reachability-fallbacks, profile missing-module (MissingModuleView, MissingModuleIT).
  2. Production: rm -rf app/src/main/bundles; mvn install -DskipTests -pl addon; mvn clean -Pit,missing-module verify -pl app.
  3. Development: mvn clean spring-boot:run -Pmissing-module -pl app, then mvn -Pit,missing-module failsafe:integration-test -pl app '-Dit.test=MissingModuleIT#u*'.
  4. The build succeeds, the build log names each left-out method with its module, and all MissingModuleIT cases pass: 11 in production, 8 in development mode.

Notes:

  • assertThrewOnServer in MissingModuleIT uses Pattern.quote, whose \Q…\E Playwright's JavaScript regex does not support. With the module escaped by hand (module.replace(".", "\\.")), all cases pass.
  • A second mvn clean -Pmissing-module package with nothing changed logs A production mode bundle build is not needed. Adding acme-does-not-exist.js makes the next build run Vite, and MissingModuleJs drops off the list of left-out functions in the stats.
API changes

All in classes for internal use only.

// com.vaadin.flow.internal.BundleUtils — Added
public static final String JS_DEFINITION_UNRESOLVED_IMPORTS_STATS_KEY
public static final String JS_DEFINITION_UNRESOLVED_IMPORTS_KEY
public static Map<String, String> getUnresolvedJsImports()
public static Map<String, String> parseUnresolvedJsImports(JsonNode node)

// com.vaadin.flow.internal.FrontendUtils — Added
public static final String JS_DEFINITION_IDS_FILE_NAME

// com.vaadin.flow.server.frontend.TaskGenerateJsDefinitions — Added
public static void updateUnresolvedImports(Options options, Collection<Class<?>> definitions)

@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Fixed the four BundleUtils findings that this PR introduced: the two caches of left-out functions are now AtomicReference fields, declared with the other static fields, and their records moved to the end of the class. The Collections.sort() in getChunkHash and the throws IOException in JsDefinitionHotswapperTest.extendedInterfaceRedefinedInPlace_... are existing code that this PR does not touch, so I left them as they are.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 1 711 files  + 1   1 801 suites  +1   2h 18m 39s ⏱️ + 4m 6s
13 983 tests +43  13 911 ✅ +43  72 💤 ±0  0 ❌ ±0 
14 661 runs  +43  14 589 ✅ +43  72 💤 ±0  0 ❌ ±0 

Results for commit 87c8264. ± Comparison against base commit f998ff9.

♻️ This comment has been updated with latest results.

mcollovati added a commit to mcollovati/skeleton-starter-flow-spring that referenced this pull request Nov 28, 2026
- MissingModuleIT: escape the module by hand, as Playwright runs the
  pattern as a JavaScript regular expression, which has no \Q...\E
- README: the baseline was the main nightly 25.5-20261128.033951, not
  9197eb4636; results on the PR (11/11, dev mode 8/8, no rebuild loop,
  installed but undeclared npm package left out)

@mcollovati mcollovati left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested with the reproducer (https://github.com/mcollovati/skeleton-starter-flow-spring/tree/repro/js-definition-reachability-fallbacks, profile missing-module, results in the README section "Modules the build can not resolve"):

  • Production: MissingModuleIT 11 of 11. The other 57 tests of the branch give the same results as before (only I13 fails, on purpose).
  • Development mode: MissingModuleIT#u* 8 of 8, and the dev bundle builds.
  • A second build with nothing changed logs A production mode bundle build is not needed. After the missing file is added, the next build runs Vite, and the stats no longer list that module.
  • The production bundle names neither the modules nor the Java classes. No @Uses advice is logged for these classes.

Thanks for the note on Pattern.quote; fixed in the reproducer (1d9f442).

@totally-not-ai about your question: yes, for an npm package that is not declared, the function should be kept and the reason logged at DEBUG level only. Leave out only ./ files that are not found. See the inline comment on FrontendModuleResolver. Please also look at the other inline comments.

|| isFrontendFolderFile(path) || hasMetaInfResource(path)) {
return null;
}
String packageName = getPackageName(path);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A package that is installed but not declared is left out. I checked it with @JsDefinitionImport(from = "@lit/reactive-element", exports = "ReactiveElement"). @lit/reactive-element is in node_modules as a dependency of lit. The build logs ... can not be found, as the npm package '@lit/reactive-element' is not a dependency of the project, which is not true: the module is there.

Looking in node_modules does not help, because this runs before npm install, so a clean CI build would leave out what a local build keeps. Please keep the function for a package that is not declared, and log the reason (interface, method, package) at DEBUG level, so that a normal build has no noise. If the package is really missing, Vite stops the build, and the Maven plugin then says to run again with -X, which shows the line. The same rule covers custom Vite aliases that look like package names. Only a ./ file that is not found should be left out.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. findUnresolvableReason now only checks ./ paths, so a bare import is never left out. A new findUndeclaredPackage names the package when the project does not declare it, and the build logs that at DEBUG level with the interface, the methods and the package. npmPackageNotDeclared_isKeptAndOnlyNamed checks that the functions stay in the file and that the debug line is logged.

Map<String, String> unresolvedImports = new TreeMap<>();
for (RenderedFunction function : functions) {
if (function.unresolved() != null) {
getLogger().error(function.unresolved().message());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: in one build each line is logged twice, because BundleValidationUtil.jsDefinitionsChanged also calls render(). It also logs one line for each method, so the three methods of MissingModuleJs in the reproducer give six ERROR lines with the same reason. One line for each interface and module (listing the methods), logged only when the file is generated, would be easier to read.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. render() no longer logs. It returns what to log, and only execute() and the hotswap path (updateUnresolvedImports) log it. There is now one line per interface and module, listing the methods, e.g. Leaving the JavaScript of the methods init, start of ...MissingModuleJs out of the bundle, so calling them fails: .... The same grouping applies to the debug lines for undeclared packages.

* an inherited method with imports that were found still works.
*/
private void checkImportsFound(JsCall call, Method method) {
Map<String, String> unresolvedImports = BundleUtils

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: this runs for every call of every definition. In development mode, getUnresolvedJsImports() reads the modification time and the size of the ids file each time, also for interfaces that have no @JsDefinitionImport. Could the check run only for methods whose declaring interface has imports (cached for each method), so that other calls do not touch the file?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. A ReflectionCache keyed by the declaring interface (cleared before hotswap) tells whether it has @JsDefinitionImport. Calls of other interfaces return before getUnresolvedJsImports(), so they don't touch the file. I cached per interface rather than per method because the build takes a method's imports from the interface that declares it. The proxy test now also calls a method of an interface without imports whose id is on the list, and checks that it still runs.

@@ -56,9 +76,30 @@ class FrontendModuleResolver {
* prefix, not <code>null</code>
*/
FrontendModuleResolver(Options options, Logger logger) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FrontendModuleResolver came with #27440 and is not released yet, so there is no need to keep this constructor. Please keep only the one that takes the packages, and pass () -> null in AbstractUpdateImports, its only caller.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Only the constructor that takes the packages is left, and AbstractUpdateImports passes () -> null.

A package that the project does not declare may still be installed as
a dependency of another package, or the module may be a Vite alias, and
whether it is installed can not be told before npm install. Only a ./
file that can not be found leaves the function out now. A package that
is not declared is logged at debug level, naming the definition, the
methods and the package; if it is really missing, Vite stops the build.

The functions left out are logged when the file is written rather than
when it is rendered, so a bundle check no longer logs them again, and
once per definition and module, listing the methods.

A call checks the list of left-out functions only when the interface
declaring the method imports modules, cached per interface, so other
calls do not read the ids file in development mode.

FrontendModuleResolver keeps only the constructor that takes the
packages, as it is not released yet.
Checks the debug line for an npm package that is not declared, the
grouped error on hotswap, that a call of an interface without imports
does not consult the list, and that a hotswap with a dev bundle keeps
the list the bundle was built with. Two tests no longer declare the
npm package their definition imports, as an undeclared one is now kept.
@totally-not-ai
totally-not-ai Bot requested a review from mcollovati November 30, 2026 07:35
Use a primitive check for the cached Boolean, List.sort() instead of
Collections.sort(), and drop an unused throws clause in a test.
getChunkHash and the hotswapper test were already like this before
this change, so they are left for a separate cleanup.
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Fixed the finding this PR introduced: JsDefinitionProxy.checkImportsFound now checks the cached Boolean with Boolean.TRUE.equals(...) instead of unboxing it. The behaviour is the same, because the cache never returns null.

I left the other two alone because that code was already on main before this PR: the Collections.sort() in BundleUtils.getChunkHash and the unused throws IOException on extendedInterfaceRedefinedInPlace_definitionsExtendingItSeeTheNewJavaScript. Sonar lists them only because the PR touches those files. They fit better in a separate cleanup.

@mcollovati

Copy link
Copy Markdown
Contributor

One more suggestion, found with the reproducer (-Pmissing-module, all the cases of the branch in one build). A production build logs 21 ERROR lines, but only 12 different ones:

  • The 3 lines of this PR (one for each interface and module) are logged once. Good.
  • The 9 older lines are logged twice: the definitions that are left out because they are wrong ("Leaving the JavaScript of {} out of the bundle: {}" in renderFunctions), and "Ignoring @JsDefinitionImport on {}" in reportMisplacedImports.

The cause is the same as before this PR: these lines are logged inside render(), and render() runs twice in one build, first from BundleValidationUtil.jsDefinitionsChanged, then from execute(). The same happens on main, so this PR does not cause it, but the PR already has the fix for its own lines: collect the problems while rendering, and log them only in execute() and updateUnresolvedImports.

Could you do the same for the other two messages? For example, renderFunctions and reportMisplacedImports could add their messages to Rendered (next to importIssues, or as one list of problems to log), and rendered.importIssues().log() in execute() would log all of them. Then jsDefinitionsChanged logs nothing, and each line is in the build output once.

mcollovati added a commit to mcollovati/skeleton-starter-flow-spring that referenced this pull request Nov 30, 2026
- U6 is now an npm package that is installed but not declared
  (@lit/reactive-element), which the build keeps
- missing-package profile: a package that is neither declared nor
  installed, which stops the Vite build
- README: results on 0ef5e484cc (11/11, dev mode 8/8, grouped ERROR
  lines, DEBUG line with -X)
A build renders the generated file twice, once to check the bundle and
once to write it. Wrong definitions and misplaced @JsDefinitionImport
annotations were logged while rendering, so each line appeared twice.
They are now collected with the import issues and logged where the file
is written, and once when a hotswap updates the list of left-out
functions.
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

@mcollovati Done. Both older messages are now handled like this PR's import lines. Rendering collects them in Rendered.issues(), which replaces importIssues(). execute() and updateUnresolvedImports log them, so the render from jsDefinitionsChanged logs nothing and each line appears once per build.

  • "Leaving the JavaScript of {} out of the bundle": renderFunctions now hands the message to an error sink instead of logging it.
  • "Ignoring @JsDefinitionImport on {}": reportMisplacedImports is now findMisplacedImports and returns the messages.
  • Hotswap: the wrong-definition message is logged once by updateUnresolvedImports. updateJsDefinitions no longer logs it a second time. Without the dev server, findMissingFromGeneratedFile logs it.
  • Tests: rendering logs nothing, and logging the issues writes each message once, in the build and on hotswap.

The recent changes from main (only package.json dependency versions) didn't require any change here.

@mcollovati

Copy link
Copy Markdown
Contributor

Thanks, each line is now logged once (checked with the reproducer).

One more suggestion for the same output. A build with several wrong definitions still logs one ERROR entry for each of them. The reproducer has 12, which is a lot to read. As all of them are now collected in Issues, could Issues.log() log one ERROR entry for each kind of message, with one item for each definition? For example:

[ERROR] Leaving the JavaScript of these definitions out of the bundle, so calling them fails:
 - org.vaadin.example.imports.AppImports$ArgumentNameJs: declares '$0' in @JsDefinitionImport(from = "./app-format.js"), which can not be imported as a name. Use a JavaScript identifier ...
 - org.vaadin.example.imports.AppImports$DuplicateNameJs: declares 'format' more than once in @JsDefinitionImport. Import one of them as a namespace
 - org.vaadin.example.missingmodule.MissingModuleView$MissingModuleJs (methods call, focus, show): the module './acme-does-not-exist.js' that it imports with @JsDefinitionImport can not be found, as no file ...
[ERROR] Ignoring @JsDefinitionImport on these classes, which only applies to an interface whose methods a definition extending JsInvokers declares:
 - org.vaadin.example.imports.AppImports$ImportOnClass
  • The modules that can not be found go into the same entry as the wrong definitions: in both cases the JavaScript is not in the bundle and calling it fails. Each item keeps its own reason and advice, so nothing is lost.
  • The items are sorted by class name, so that the output is the same in every build.
  • The hotswap path uses the same log(), so a single changed definition gives an entry with one item.
  • Nothing is logged when there are no items.

@mcollovati

Copy link
Copy Markdown
Contributor

A small change for the same output: the text of Ignoring @JsDefinitionImport on {} in reportMisplacedImports is hard to read, mainly the end: which only applies to an interface whose methods a definition extending JsInvokers declares.

The message is logged only when the annotation is on a class, so it can say that directly, and then say where the annotation goes. For one class:

Ignoring @JsDefinitionImport on org.vaadin.example.imports.AppImports$ImportOnClass, because it is a class. Put the annotation on the interface whose methods use the imported names: a definition that extends JsInvokers, or an interface it extends

With the grouped entry of my previous comment:

[ERROR] Ignoring @JsDefinitionImport on these classes, as the annotation works only on interfaces. Put it on the interface whose methods use the imported names: a definition that extends JsInvokers, or an interface it extends.
 - org.vaadin.example.imports.AppImports$ImportOnClass

Could you change it together with the grouping?

A build with many wrong definitions logged one ERROR entry for each.
The definitions left out because what they declare is wrong and those
left out because a module they import can not be found now share one
entry, one item per definition sorted by name, and the misplaced
@JsDefinitionImport annotations another. Nothing is logged when there
is nothing to list.
An item no longer repeats the definition name that the reason starts
with, and the debug line about an undeclared npm package names the
methods the same way as the error items.
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

On the documentation finding: the from() paragraph of @JsDefinitionImport now says that a ./ file the build can not find leaves the methods of the annotated interface out of the bundle, and that each call of such a method throws an IllegalStateException on the server naming the module, while the rest of the application keeps working. It also says that npm packages are not looked for. Element.executeJs(Class) now names this as the one case that fails at the call rather than when the implementation is handed out.

The latest changes from main only touch guidelines/architecture.md (signal effects and the session lock), so nothing here needed adapting.

mcollovati
mcollovati previously approved these changes Nov 30, 2026
@mcollovati
mcollovati enabled auto-merge November 30, 2026 12:09

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 1 comment.

Finding
🧪 No test fails if the isInGeneratedFile fix for the dev-bundle regression is removed


classesChanged(MissingModuleGreeterJs.class);

assertEquals(List.of(MissingModuleGreeterJs.class.getName()),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 No test fails if the isInGeneratedFile fix for the dev-bundle regression is removed

This case never writes vaadin-js-definitions.js, so findMissingFromGeneratedFile returns the definition through the generated == null guard, before the new left-out check is reached. The assertion holds equally on the pre-fix code.

updateUnresolvedImports_followsTheDefinitionsThatChanged does not close the gap either: its findMissingFromGeneratedFile assertion is satisfied because FoundImportMixin.run is absent from a file rendered for GreeterJs/PopoverJs only, again without consulting the left-out list.

Writing the generated file first (e.g. writeGeneratedDefinitionsFor(GreeterJs.class)) would exercise the real path: MissingModuleGreeterJs has a single method, so without the fix declared is empty, isInGeneratedFile answers "present", and nothing is reported.

JsDefinitionHotswapperTest.java:389 · tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. definitionImportingAModuleNotFound_devBundle_listKeptAsBuilt now writes the generated file for GreeterJs first, so the check reaches the left-out list instead of stopping at the missing-file guard. MissingModuleGreeterJs renders no lines into that file. I checked that the test fails when the left-out check in isInGeneratedFile is removed and passes with it.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — collected 1 finding below that could not be attached to the diff.

Finding
📝 Page.executeJs(Class) does not document the new per-call IllegalStateException

📝 Page.executeJs(Class) does not document the new per-call IllegalStateException
Page.executeJs(Class) goes through the same JsDefinitionProxy.create, so a method whose module the build could not find throws on every call here too. Only Element.executeJs(Class) got the new paragraph about it; the Page javadoc still describes the contract as "nothing about the JavaScript is decided at the call site" and lists IllegalArgumentException as the only failure.
Page.java:581 · documentation

@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Added the same paragraph to Page.executeJs(Class) as to Element.executeJs(Class): the interface is checked when the implementation is handed out, except for a method whose JavaScript the build left out because a module it imports with @JsDefinitionImport can not be found. Each call of such a method throws an IllegalStateException naming the module, while the other methods keep working.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Nothing to flag — the changes look good.

@sonarqubecloud

Copy link
Copy Markdown

@mcollovati
mcollovati added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit 50c7ad3 Nov 30, 2026
57 checks passed
@mcollovati
mcollovati deleted the issue-27424-unresolved-js-definition-imports branch November 30, 2026 14:15
@github-actions

Copy link
Copy Markdown
Contributor

Documentation Bot: No documentation needed for this change.

This is a BEHAVIOR_CHANGE/NEW_FEATURE: a @JsDefinitionImport of a missing ./ file no longer fails the whole build; only the methods that use it are left out (logged with the interface, methods, and module), and calling one of them throws an IllegalStateException on the server naming the module, while the rest of the application keeps working. The javadoc of @JsDefinitionImport, Element.executeJs(Class), and Page.executeJs(Class) was updated to say so. The rest of the diff (BundleUtils, FrontendModuleResolver, TaskGenerateJsDefinitions, the hotswapper) is internal build/runtime plumbing with no public API outside those internal classes.

I could not find a page in vaadin/docs that already documents @JsDefinitionImport itself (the import feature for @JsDefinition interfaces, added in 25.5) to extend with this failure mode — calling-javascript.adoc covers @JsDefinition/JsInvokers/executeJs(Class) but never mentions @JsDefinitionImport. Writing only about the new graceful-degradation behavior without the base annotation it modifies would be incoherent to a reader and is a larger documentation gap that predates this pull request.

Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.

Generated by Documentation Bot for #27491 · agent · 87.6 AIC · ⊞ 11.7K · ◷

totally-not-ai Bot added a commit that referenced this pull request Nov 30, 2026
Also say in Page.executeModuleJs that its modules load with the views,
unlike those of executeJs(Class), and have the development warning
name a path the build could not check rather than a missing file, which
since #27491 fails on the server instead.
mcollovati pushed a commit that referenced this pull request Dec 1, 2026
…27491) (CP: 25.4)

Fixes #27424
Part of #25814

**build failure** · flow-build-tools, flow-server, vaadin-dev-server ·
applications with a `@JsDefinitionImport` of a `./` file the build can
not find

A `@JsDefinitionImport` of a missing `./` file used to stop the
production build, and in development mode every page showed that the dev
server failed to start. The messages did not name the Java interface.
Now only the methods that import the missing file are left out. The
build log says which interface, methods and module, and why. Calling
such a method throws on the server, every time, naming the module. The
rest of the application works.

**Risks:**
- ⚠️ Only `./` files are checked. An npm package the project does not
declare is kept, as it may be installed as a dependency of another
package or be a Vite alias, which can not be told before npm install.
The build logs it at DEBUG level, naming the interface, methods and
package. If the package is really missing, Vite stops the build as
before, and running again with `-X` shows that line.
- ✅ No public API change outside internal classes, no serialization,
threading or memory impact. A production server reads the list once from
the stats. A development server reads it again only when the file
changes, and only for calls of methods whose interface has
`@JsDefinitionImport`.

- Added a check before Vite runs: a `./` path is looked for in the
frontend folder with the extensions and index files Vite tries, and in
`META-INF/frontend` / `META-INF/resources/frontend` of the class path as
named.
- The functions of such methods are left out of the generated file, in
the build and when the frontend dev server picks up a hotswapped
definition. Their ids are recorded with the module in
`vaadin-js-definition-ids.json` and in the bundle stats
(`jsDefinitionUnresolvedImports`), keyed by function id, so the
production bundle names no Java class.
- Without the frontend dev server, the list stays as the bundle was
built. A hotswapped definition that now imports a missing file is
reported as not applied, with the advice to restart, and the module is
logged.
- The Javadoc of `@JsDefinitionImport`, `Element.executeJs(Class)` and
`Page.executeJs(Class)` says that such a method throws at each call
while the rest keeps working.
- What is left out of the bundle is logged as one ERROR entry with one
item per definition, sorted by class name. This covers definitions whose
module can not be found (naming the methods and module) and definitions
that declare something wrong. `@JsDefinitionImport` on a class gets a
second entry listing the classes. Nothing is logged when there is
nothing to list.
- These entries are logged only when the file is written, and once on
hotswap. Before, the bundle check logged the older messages a second
time, because it renders the file too.
- `JsDefinitionProxy` throws `IllegalStateException` when such a method
is called. The check runs per call, so an inherited method with imports
that are found still works. It looks at the list only when the interface
declaring the method has imports, cached per interface. Stats without
the entry fall back to the check from #27078.
- The bundle is rebuilt when the list of left-out functions differs from
the stats, or when a missing module appears. Left-out functions do not
count as missing, so an unchanged project does not rebuild.
- The check from #27078 no longer advises `@Uses` for left-out
functions.
- Existing tests that imported `./` files they never created now create
them, as such imports are left out now.

Working on behalf of @mcollovati

---------

Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
mcollovati pushed a commit that referenced this pull request Dec 1, 2026
…n a class (#27568) (CP: 25.4)

Fixes #27554
Follow-up to #27491

**behavior deviation** · flow-build-tools, flow-server,
vaadin-dev-server · applications or add-ons with a `@JsDefinitionImport`
of a `./` file that the build can not find, or with one on a class

A `@JsDefinitionImport` of a missing `./` file now stops the build in
production and development mode, like a missing `@JsModule` file.
Before, the build passed with one ERROR line and each call of the
affected methods threw on the server. The error names the interface, the
methods and the module. A `@JsDefinitionImport` on a class, which no
definition can extend, now stops the build too, instead of being ignored
with an error in the log. An optimized production build checks only the
classes that the application reaches, as it does for definitions.

**Risks:**
- ⚠️ Behaviour change: a broken add-on, with a missing module or with
`@JsDefinitionImport` on a class, now stops the build of every
application that uses it, as a missing `@JsModule` file already does.
`@JsDefinitionImport` (#27457) and the lenient handling (#27491) are not
in any release, so no released code depends on it.
- ✅ Only internal API is removed (all added in #27491, unreleased). No
change to serialization, threading, memory or performance.

**Context.** #27491 left such methods out so that one broken add-on
would not break every build. Nothing else in Flow works that way, and a
CI log line is easy to miss. The check that runs before Vite is kept,
because Vite's own error does not name the Java interface. npm packages
are still assumed to be found when in doubt.

- `TaskGenerateJsDefinitions` throws `ExecutionFailedException` listing
each definition, its methods and the module. The methods are rendered as
usual, so the bundle check asks for a rebuild and the build reaches this
failure.
- Removed the left-out list from `vaadin-js-definition-ids.json` and the
bundle stats, the per-call `IllegalStateException` in
`JsDefinitionProxy`, the bundle-check special case and the `@Uses` check
exception. Also removed
`BundleUtils.getUnresolvedJsImports`/`parseUnresolvedJsImports`, their
keys, `FrontendUtils.JS_DEFINITION_IDS_FILE_NAME` and
`TaskGenerateJsDefinitions.updateUnresolvedImports`.
- A `@JsDefinitionImport` on a class now fails the build in the same
message as missing modules, naming the classes and saying where the
annotation goes. This also applies when the class comes from a jar. With
the bytecode scanner, a production build checks only the classes that
the application reaches, so an unused add-on class does not break the
build. Development mode checks every class. Updated the Javadoc of
`@JsDefinitionImport` and `findMisplacedImports`.
- Hotswap: a method whose module can not be found is not written to the
dev server file. The same error is logged, followed by what to do once
the module is added: restart the application, or, with the frontend dev
server, change the definition again. Adding the file alone does not
write the JavaScript. Only the function with the missing module is left
out, and the other functions of the definition are written, also when
the file is written from scratch. The hotswapper does not also warn
about the definition.
- Updated the Javadoc of `@JsDefinitionImport`,
`Element.executeJs(Class)`, `Page.executeJs(Class)`,
`Page.executeModuleJs(Class)` and `JsModuleInvokers`.
- Removed the tests of the left-out list and of the per-call throw.
Tests now check: the build fails in both modes with the message; the
module that a `JsModuleInvokers` interface calls (`this`) is covered
too; the bundle is rebuilt; and hotswap logs the error without writing
the import, with or without an existing file. The existing test for the
annotation on a class, and the test for the issue message format, now
expect the build to fail instead of an error in the log.

Working on behalf of @mcollovati

---------

Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Report JavaScript definition imports that can not be resolved on the server

3 participants