quarkiverse / quarkus-web-bundler

Create full-stack web apps quickly and easily with this Quarkus extension. It offers zero-configuration bundling for your web app scripts (JS, JSX, TS, TSX), dependencies (jQuery, React, htmx, etc.), and styles (CSS, SCSS, SASS).
Apache License 2.0
16 stars 9 forks source link

Bundling does not work in multi module #244

Open gbourant opened 4 days ago

gbourant commented 4 days ago

I have the following multi module project https://github.com/gbourant/multi-bundler-bug

It consists of project-a and project-b.

project-a works as expected. the main.js gets bundled.

project-b has a dependency to project-a. if you try to run project-b you get the following error:

ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
    [error]: Build step io.quarkiverse.web.bundler.deployment.DevModeBundlingProcessor#watch threw an exception: io.mvnpm.esbuild.BundleException: Error during bundling: 

✘ [ERROR] Could not resolve "htmx.org/dist/htmx.esm.js"
    app/main.js:3:17:
      3 │ import htmx from 'htmx.org/dist/htmx.esm.js';
        ╵                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
 You can mark the path "htmx.org/dist/htmx.esm.js" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

1 error
[watch] build finished, watching for changes...
    at io.mvnpm.esbuild.Execute$Streamer.lambda$run$0(Execute.java:150)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    ... 1 more
ia3andy commented 4 days ago

You shouldn't use web-dependency-locator and the web-bundler together, they serve the same goal.

You can use:

quarkus.web-bundler.dependencies.auto-import=all

then you don't need the app.js

If you wish to keep the app.js, just do import 'htmx.org';, it should be enough to use it.

To make the second module work you should add the dependency for htmx again since it's provided (non transitive)

gbourant commented 4 days ago

Alright, i removed the web-dependency-locator.

Since the version 2.0.0 of htmx, the htmx library is not available at the windows object see https://github.com/bigskysoftware/htmx/issues/2628#issuecomment-2176677081

So in my case quarkus.web-bundler.dependencies.auto-import=all and import 'htmx.org'; is not useful.

Well, when i added the htmx to second's module pom.xml it worked but that doesn't make it work out of the box.

Instead, when i used quarkus.web-bundler.dependencies.compile-only=false (in project-a), it made it work out of the box. (but that made the target directory little bigger)

I don't know which option i will use at the end, but at least now i got 2 options that make it work.

ia3andy commented 4 days ago

You still have this workaround: https://github.com/quarkiverse/quarkus-web-bundler/issues/84#issuecomment-1830064303