Repository navigation
Description
Description
Since #27491 (for #27424), when the build can not find the module of a @JsDefinitionImport, it leaves the methods that use it out of the bundle and logs an error. The build passes. Each call of such a method then throws an IllegalStateException on the server.
The reason for this was that one broken add-on should not break the build of every application that has it on the class path. But Flow does not do this anywhere else:
- A
@JsModule("./x.js")file that can not be found stops the build (AbstractUpdateImports.getUniqueEs6ImportPathsthrows anIllegalStateException). This is true for add-ons too. - A wrong
@JsStringFallbackstops the build. - An undeclared npm package in
@JsDefinitionImportis kept, so Vite stops the build (changed during the review of feat: report JavaScript definition imports that can not be resolved #27491).
So now a missing ./ file in @JsDefinitionImport is the only case that does not stop the build.
Stopping the build is also better for users:
- The add-on developer sees the problem before the release. Today their build passes with one ERROR line, which is easy to miss in CI. They only see the problem if a test calls the broken method.
- The application developer sees the problem before deploying. They can not fix a broken add-on in either case: they must wait for a fix or use an older version. With a failed build they find out at build time, not when a user clicks something in production.
#27491 is not released yet, so this can change without deprecation.
@JsDefinitionImport on a class
The same reason is used for a @JsDefinitionImport on a class. No definition can extend a class, so the import is never used. Since #27457 (made one grouped entry in #27491), the build ignores the annotation and logs an error ("Ignoring @JsDefinitionImport on this class, as the annotation works only on interfaces..."). The Javadoc of TaskGenerateJsDefinitions.findMisplacedImports gives the reason: failing the build "would break every application that has the class on its class path, an add-on its developer can not fix among them". The arguments above apply here too, so this mistake should also stop the build.
Proposal
When the module of a @JsDefinitionImport can not be found, stop the build in production and in development mode, as for @JsModule.
- Keep the check that runs before Vite (
FrontendModuleResolver.findUnresolvableReason). Vite's own message does not name the Java interface, but the check's message does. The message should name the interface, the methods and the module. - Keep the current rule for npm packages: if in doubt, treat the module as found.
- Remove the parts that only exist for the lenient behavior:
- the unresolved-imports entry in
vaadin-js-definition-ids.jsonand in the bundle stats (BundleUtils.JS_DEFINITION_UNRESOLVED_IMPORTS_STATS_KEY,JS_DEFINITION_UNRESOLVED_IMPORTS_KEY,getUnresolvedJsImports,parseUnresolvedJsImports) - the per-call check in the invocation handler that throws the
IllegalStateException - the special cases in
BundleValidationUtil.jsDefinitionsChangedand in the@Usescheck from feat: log error for JavaScript definitions missing from bundle #27078 TaskGenerateJsDefinitions.updateUnresolvedImportsand the hotswap path that updates the list. On hotswap, a module that can not be found should give the same error as a hotswap that adds a missing@JsModule.
- the unresolved-imports entry in
- Update the Javadoc of
@JsDefinitionImport,Element.executeJs(Class),Page.executeJs(Class),Page.executeModuleJsandJsModuleInvokers: they now say that the build leaves the method out and that each call throws. - Also stop the build for a
@JsDefinitionImporton a class (findMisplacedImports), in production and in development mode, with the current message: it names the classes and says where to put the annotation. Update the Javadoc offindMisplacedImportsand the part of the@JsDefinitionImportJavadoc that says the annotation "is ignored, with an error in the log of the build, on a class".
Tests
- A missing
./file in@JsDefinitionImportstops the build. The message names the interface, the methods and the module. - The same in development mode (the dev bundle build or the Vite dev server reports the error).
- A module that is found (project file, jar file, file without extension, declared npm package) still builds.
- A
@JsDefinitionImporton a class stops the build, also when the class comes from a jar. The message names the class. - Reproducer: https://github.com/mcollovati/skeleton-starter-flow-spring/tree/repro/js-definition-reachability-fallbacks, profile
missing-module. Its tests then change from "the call throws" to "the build fails".
Activity
totally-not-ai commentedon Dec 1, 2026
Triage: valid request. Not done on the default branch yet. The lenient behaviour is only on
main(not on25.4or any release), so it can change without deprecation.Why it fits: a missing
./file in@JsDefinitionImportis today the only missing frontend module that lets the build pass. A missing@JsModulefile, even in an add-on, stops the build.Caveat: definitions that fail the definition check are also left out of the bundle with only an ERROR line. The same consistency argument applies to them, but the proposal does not cover them.
Caveat: open PR feat: load JsModuleInvokers modules with the views that use them #27493 depends on the current behaviour. Its description says a missing
./file "never gets there" because the methods are left out. One of the two PRs has to be adjusted, depending on which lands first.Next step: fail the build (production and development) when such a module can not be found, keep the check's message that names the interface, methods and module, and remove the left-out list, the per-call throw and the hotswap path, as the issue proposes. Before I open a PR, a maintainer should answer:
One reply from a maintainer on this issue mentioning
@totally-not-ai(e.g.@totally-not-ai do it, or@totally-not-ai 1: separate, 2: yes) is enough for me to open a PR. Others are welcome to weigh in.Where the lenient behaviour lives
TaskGenerateJsDefinitions(render) andfindUnresolvedImport. The ERROR is logged byIssues.log()in the same class.execute()andupdateUnresolvedImportsinTaskGenerateJsDefinitions, called fromJsDefinitionHotswapper.BundleUtils(JS_DEFINITION_UNRESOLVED_IMPORTS_*,getUnresolvedJsImports,parseUnresolvedJsImports) andBundleValidationUtil.jsDefinitionsChanged.JsDefinitionProxy.checkImportsFound.@JsModulebehaviour:AbstractUpdateImports.getUniqueEs6ImportPathsthrows when a file can not be found.Issues.log()path ("Leaving the JavaScript of this definition out of the bundle, so calling it fails").mcollovati commentedon Dec 1, 2026
@totally-not-ai 1: separate, 2: yes
[-]Fail the build when a `@JsDefinitionImport` module can not be found[/-][+]Fail the build for a missing `@JsDefinitionImport` module or an import on a class[/+]totally-not-ai commentedon Dec 1, 2026
@mcollovati Done: draft PR #27568 is open.
./module that can not be found now stops the build in production and development mode. The error names the interface, the methods and the module.mcollovati commentedon Dec 1, 2026
@totally-not-ai the draft PR should also take into account the
@JsDefinitionImporton a class case added to the issue bodyfix: fail the build for @JsDefinitionImport on a class
totally-not-ai commentedon Dec 1, 2026
@mcollovati Done, it is pushed to #27568.
@JsDefinitionImporton a class now stops the build in production and development mode, also when the class comes from a jar. It is no longer ignored with an error in the log.@JsDefinitionImportandfindMisplacedImportsis updated. The PR title and description now cover this case.fix: fail the build for a missing @JsDefinitionImport module or one o…