Error Building for production - 24.1.4

Hello,

Until now I’ve used 24.1.2 and I could build for prod with : versions:set -DnewVersion=1.0.0-SNAPSHOT package -Pproduction

Today I’ve tried upgrading to 24.1.4 and it shows errors on while running(one of):
2023-08-03T20:59:46.770+03:00e[0;39m e[31mERRORe[0;39m e[35m26238e[0;39m e[2m—e[0;39m e[2m[nio-8080-exec-9]e[0;39m e[36mc.v.flow.component.internal.UIInternals e[0;39m e[2m:e[0;39m The component class com.vaadin.flow.component.checkbox.Checkbox includes ‘@vaadin/checkbox/src/vaadin-checkbox.js’ but this file was not included when creating the production bundle. The component will not work properly. Check that you have a reference to the component and that you are not using it only through reflection. If needed add a @Uses(Checkbox.class) where it is used.

Is there anything I need to add in this version to make this work ?

Hi and thanks for reporting your problem. A couple of questions to better understand what is hapening: does Flow builds a new bundle for you or does it say that it can re-use a precompiled prod bundle (should be visible in the server logs) ? Could you check that the ‘@vaadin/checkbox/src/vaadin-checkbox.js’ is available in the node_modules (in case Flow rebuilds a bundle for you) ?

I also you can try to run mvn clean; mvn vaadin:clean-frontend to clean up the project and rerun the build.

Also check if a reflection is used in your project to instantiate the Checkbox component, if it’s a case for you, you have to use @Uses as proposed in the error message above.

Hello,
ATM I’m traveling, I cannot post any logs, I tried with clean build, still the same. Yes, I use reflection to instantiate all my stuff(the base is just 4-5 classes)

I’ll be back with logs in maximum 2 days

If you only use reflection to build your views, the above mentioned annotation is required - and was always required - looks like you just got lucky that a bug helped you in the past

I’m back,
So, my app worked 3 and a half years out of the box because of a bug ? WOW lol
**A story to scare the senior devs lol
Well, I used @Uses annotation on one test class, and JsModule(“@vaadin/checkbox/src/vaadin-checkbox.js”) But I still get:
e[2m2023-08-08T20:55:13.151+03:00e[0;39m e[31mERRORe[0;39m e[35m38754e[0;39m e[2m—e[0;39m e[2m[nio-8080-exec-6]e[0;39m e[36mc.v.flow.component.internal.UIInternals e[0;39m e[2m:e[0;39m The component class something secret includes ‘@vaadin/checkbox/src/vaadin-checkbox.js’ but this file was not included when creating the production bundle. The component will not work properly. Check that you have a reference to the component and that you are not using it only through reflection. If needed add a @Uses(MyClass.class) where it is used.

Also I included MyClass.class

Well… the frontend part got improved to only include stuff that you are really using (checked with code scanning) - in the past the prod bundle included “none used” stuff, which is a “bug” / side effect. You can go back to that “mode” with “optimizeBundle” set to false - see https://vaadin.com/docs/latest/production/production-build

Even tho it would be interesting for the flow guys how EXACTLY you are building your views to understand what exactly goes wrong here.

I use an ENUM Class with all my packages then I have from a combobox a listener that instanciates the stuff I need

        clazz = Class.forName(Models.getClassName(cid));

        Field field = clazz.getDeclaredField("NAME");

        if (clazz.asSubclass(Component.class) != null) {
            RouteConfiguration.forSessionScope().setRoute(field.get(clazz).toString(),
                (Class<? extends Component>) clazz);
            VaadinSession.getCurrent().setAttribute("class", clazz.getName());
            submit.getUI().ifPresent(ui -> ui.navigate((Class<? extends Component>) clazz));
        }

        } catch (Exception e) {

        e.printStackTrace();
        }```

Yeah that’s 100% not going to work without the optimize set to false :sweat_smile:

There was a similar setup some weeks ago: https://github.com/vaadin/flow/issues/17219#issuecomment-1653540668 (cc @versatile-zorse cause of his comment there)

ok, I think I understand,

Let me try make it false and see :slightly_smiling_face:

Yep, it worked !

Thank you :slightly_smiling_face: