Skip to content

Fail the build for a missing @JsDefinitionImport module or an import on a class #27554

Done

Description

@mcollovati

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.getUniqueEs6ImportPaths throws an IllegalStateException). This is true for add-ons too.
  • A wrong @JsStringFallback stops the build.
  • An undeclared npm package in @JsDefinitionImport is 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.json and 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.jsDefinitionsChanged and in the @Uses check from feat: log error for JavaScript definitions missing from bundle #27078
    • TaskGenerateJsDefinitions.updateUnresolvedImports and 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.
  • Update the Javadoc of @JsDefinitionImport, Element.executeJs(Class), Page.executeJs(Class), Page.executeModuleJs and JsModuleInvokers: they now say that the build leaves the method out and that each call throws.
  • Also stop the build for a @JsDefinitionImport on 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 of findMisplacedImports and the part of the @JsDefinitionImport Javadoc that says the annotation "is ignored, with an error in the log of the build, on a class".

Tests

  • A missing ./ file in @JsDefinitionImport stops 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 @JsDefinitionImport on 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

  1. totally-not-ai commented on Dec 1, 2026

    @totally-not-ai
    Contributor

    Triage: valid request. Not done on the default branch yet. The lenient behaviour is only on main (not on 25.4 or any release), so it can change without deprecation.

    • Why it fits: a missing ./ file in @JsDefinitionImport is today the only missing frontend module that lets the build pass. A missing @JsModule file, 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:

      1. Should definitions that fail the definition check also stop the build? (recommended: yes, but in a separate issue/PR so this one stays a straight revert of the lenient path)
      2. Land this before feat: load JsModuleInvokers modules with the views that use them #27493 and adjust feat: load JsModuleInvokers modules with the views that use them #27493 afterwards? (recommended: yes)

      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
    • Leaving the method out: TaskGenerateJsDefinitions (render) and findUnresolvedImport. The ERROR is logged by Issues.log() in the same class.
    • The list written next to the generated file and read back on hotswap: execute() and updateUnresolvedImports in TaskGenerateJsDefinitions, called from JsDefinitionHotswapper.
    • The bundle stats entry and its comparison: BundleUtils (JS_DEFINITION_UNRESOLVED_IMPORTS_*, getUnresolvedJsImports, parseUnresolvedJsImports) and BundleValidationUtil.jsDefinitionsChanged.
    • The throw at each call: JsDefinitionProxy.checkImportsFound.
    • For comparison, the @JsModule behaviour: AbstractUpdateImports.getUniqueEs6ImportPaths throws when a file can not be found.
    • The definition check failures (question 1) go through the same Issues.log() path ("Leaving the JavaScript of this definition out of the bundle, so calling it fails").
  2. mcollovati commented on Dec 1, 2026

    @mcollovati
    ContributorAuthor

    @totally-not-ai 1: separate, 2: yes

  3. changed the title [-]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[/+] on Dec 1, 2026
  4. totally-not-ai commented on Dec 1, 2026

    @totally-not-ai
    Contributor

    @mcollovati Done: draft PR #27568 is open.

    • A ./ 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.
    • The left-out list, the throw on each call and the bundle-check special cases are removed. npm packages still count as found when in doubt.
    • On hotswap, the import is not written to the dev server file and the same error is logged. The definition is not reported as fixed by a restart, because the restart would fail too.
    • Definitions that fail the definition check are unchanged, as you decided (separate issue).
    • Next step: review fix: fail the build for a missing @JsDefinitionImport module or one on a class #27568.
  5. mcollovati commented on Dec 1, 2026

    @mcollovati
    ContributorAuthor

    @totally-not-ai the draft PR should also take into account the @JsDefinitionImport on a class case added to the issue body

  6. totally-not-ai commented on Dec 1, 2026

    @totally-not-ai
    Contributor

    @mcollovati Done, it is pushed to #27568.

    • A @JsDefinitionImport on 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.
    • The build reports it in the same error as missing modules, naming the classes and saying where the annotation goes.
    • The Javadoc of @JsDefinitionImport and findMisplacedImports is updated. The PR title and description now cover this case.
    • Next step: review fix: fail the build for a missing @JsDefinitionImport module or one on a class #27568.
  7. added a commit that references this issue on Dec 1, 2026
    b545d40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions