Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weird java compilation error when using :target :bundle #247

Closed
gdanov opened this issue May 26, 2020 · 25 comments
Closed

weird java compilation error when using :target :bundle #247

gdanov opened this issue May 26, 2020 · 25 comments

Comments

@gdanov
Copy link

gdanov commented May 26, 2020

Hi,
I have working project that targets browser. Due to one dependency that's not properly bundled (has require() in it) I decided to give the new :bundle target a go.
Problem is, once I switch the target, I get the exception bellow very early in the start. I have disabled all the custom parts of the build I have, but still same exception.

[Figwheel] Compiling build dev to "target/public/cljs-out/dev-main.js"
[Figwheel] Failed to compile build dev in 0.206 seconds.
[Figwheel:WARNING] Compile Exception: contains? not supported on type: java.lang.Boolean
[Figwheel:SEVERE] java.lang.IllegalArgumentException: contains? not supported on type: java.lang.Boolean

here is the config as seen by figwheel:

[Figwheel:FINEST] Verbose config: {:figwheel.main/build
 {:id "dev",
  :config
  {:open-url false,
   :watch-dirs ["src/shared" "src/front"],
   :log-level :all,
   :ring-handler handler/handler}},
 :ns experiment.core,
 :figwheel.main/join-server? false,
 :figwheel.main/post-build-hooks
 (#function[figwheel.main/config-cljsc-opts-json/fn--7922]),
 :figwheel.main/initializers
 [#function[figwheel.main/config-figwheel-mode?/fn--7719]
  #function[figwheel.main/config-system-exit/fn--7830]],
 :repl-env-options
 {:ring-handler #'handler/handler,
  :open-url false,
  :connection-filter
  #function[figwheel.main/config-repl-connect/fn--7791],
  :output-to "target/public/cljs-out/dev-main.js",
  :output-dir "target/public/cljs-out/dev",
  :target :bundle,
  :ring-stack-options
  #:figwheel.server.ring{:dev
                         #:figwheel.server.ring{:system-app-handler
                                                #function[figwheel.main/add-default-system-app-handler/fn--8067/fn--8068]}}},
 :figwheel.main/config
 {:mode :repl,
  :open-url false,
  :watch-dirs ("src/shared" "src/front"),
  :log-level :all,
  :ring-handler #'handler/handler,
  :figwheel.main/build-inputs ["src/shared" "src/front"]},
 :options
 {:output-dir "target/public/cljs-out/dev",
  :closure-defines
  #:figwheel.repl{connect-url
                  "ws://localhost:9500/figwheel-connect?fwprocess=4e9b4f&fwbuild=dev"},
  :install-deps true,
  :optimizations :none,
  :aot-cache false,
  :preloads
  [example.procstub
   example.devcardsentry
   figwheel.core
   figwheel.main
   figwheel.repl.preload
   devtools.preload
   figwheel.main.system-exit],
  :figwheel true,
  :output-to "target/public/cljs-out/dev-main.js",
  :asset-path "/cljs-out/dev",
  :bundle-cmd
  {:none ["npx" "webpack" "--mode=development"],
   :default ["npx" "webpack"]},
  :repl-requires
  ([figwheel.repl :refer-macros [conns focus]]
   [figwheel.main
    :refer-macros
    [stop-builds start-builds build-once reset clean status]]
   [cljs.pprint :refer [pprint] :refer-macros [pp]]
   [cljs.repl :refer-macros [source doc find-doc apropos dir pst]]),
  :target :bundle,
  :devcards true,
  :main experiment.core,
  :npm-deps
  {"react-reconciler" "0.25.1",
   "react" "16.9.0",
   "react-dom" "16.9.0",
   "paper" "0.12.4"}},
 :repl-options
 {:output-dir "target/public/cljs-out/dev",
  :closure-defines
  #:figwheel.repl{connect-url
                  "ws://localhost:9500/figwheel-connect?fwprocess=4e9b4f&fwbuild=dev"},
  :inits [{:type :init-forms, :forms nil}],
  :install-deps true,
  :optimizations :none,
  :aot-cache false,
  :preloads
  [example.procstub
   example.devcardsentry
   figwheel.core
   figwheel.main
   figwheel.repl.preload
   devtools.preload
   figwheel.main.system-exit],
  :figwheel true,
  :output-to "target/public/cljs-out/dev-main.js",
  :asset-path "/cljs-out/dev",
  :bundle-cmd
  {:none ["npx" "webpack" "--mode=development"],
   :default ["npx" "webpack"]},
  :repl-requires
  ([figwheel.repl :refer-macros [conns focus]]
   [figwheel.main
    :refer-macros
    [stop-builds start-builds build-once reset clean status]]
   [cljs.pprint :refer [pprint] :refer-macros [pp]]
   [cljs.repl :refer-macros [source doc find-doc apropos dir pst]]),
  :analyze-path ["src/shared" "src/front"],
  :target :bundle,
  :devcards true,
  :npm-deps
  {"react-reconciler" "0.25.1",
   "react" "16.9.0",
   "react-dom" "16.9.0",
   "paper" "0.12.4"}}}
@bhauman
Copy link
Owner

bhauman commented May 26, 2020

hmmm is there any way that you can get me a stacktrace?

A couple of trouble shooting tips.

Also, there is a different subtle problem, your :output-to needs to be in the :output-dir directory so that the bundle can bundle it. In your case it should be "target/public/cljs-out/dev/main.js". I'm currently writing this up in the docs. I'll also push out the latest SNAPSHOT.

But I could really use that stacktrace.

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

You can also troubleshoot by removing :bundle-cmd running webpack from the command line to see if the compile completes and to check that npx webpack is working

@gdanov
Copy link
Author

gdanov commented May 26, 2020

Thanks for the prompt reply. My debugging shows that this is where the exception is being fired

the output folder is not a problem yet, I'm not getting there. I tried removing the bundle command, changes nothing. I'll spend some time now trying to figure out why cljs is getting structure it does not seem to be expecting

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

OK so that is in the CLJS compiler and it refers to how you are requiring an NPM library I think.

So I'd look for the offensive require and then file a report or ask on slack on cljs-dev

@gdanov
Copy link
Author

gdanov commented May 26, 2020

OK so that is in the CLJS compiler and it refers to how you are requiring an NPM library I think.

So I'd look for the offensive require and then file a report or ask on slack on cljs-dev

require in what part of the code/config? I for sure have react conflicts

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

So it's not Figwheel that's causing this error. Which is good to hear :)

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

Its somewhere in an ns where you use (:require [react-or-some-npm-lib]) to include an NPM library.

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

You could just make a tiny cljs.main project and try to require each of the npm libraries you need. This will be helpful to learn what the pattern is.

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

Wait, I see something. I see you're using :npm-deps that might be it. It may have something to do with figwheel. Hold on.

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

Remove the :install-deps key. Also I'm worried that :npm-deps is getting set to false. It shouldn't be.

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

It's probably best to use npm and your package.json directly

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

Yes I think that is it.

@gdanov
Copy link
Author

gdanov commented May 26, 2020

pls have a look at the variable values, maybe that helps. It's the same call, two different places in the call stack.

Screenshot 2020-05-26 at 17 30 11

Screenshot 2020-05-26 at 17 32 14

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

yes I see, what were the opts before they went through (add-implicit-opts opts)

@gdanov
Copy link
Author

gdanov commented May 26, 2020

I believe this is where the perfectly valid :npm-deps are replaced with true

Screenshot 2020-05-26 at 17 36 21

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

https://github.com/clojure/clojurescript/blob/master/src/main/clojure/cljs/closure.clj#L2508
yep just found it myself

:npm-deps doesn't work with :bundle target

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

We should warn for that shit :)

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

I think that's this is because :npm-deps true causes a scan of the node modules. It's not really a declaration of dependencies.

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

I'm about to release 0.2.6 and along with some docs on how to use the new Bundle feature.
I'm on Slack now BTW if you need more help with this.

@gdanov
Copy link
Author

gdanov commented May 26, 2020

First, thanks for the :output-to hint. I got the thing running.

I read the article announcing :target :bundle and imagined it's some sort of next level npm integration, so kinda expected to get better UX for :npm-deps. Frankly, the consumption of npm modules by clojurescript has been pain in the butt since day one, and even though I got fairly proficient with the JS ecosystem by doing JS fullstack work for a while, it's still often very confusing to know what combination of options works in which context (fully aware that's in cljs's yard) so I'd love to see figwheel-main as one-stop-shop where I can start web project with minimal overture.

I'm about to release 0.2.6 and along with some docs on how to use the new Bundle feature.
I'm on Slack now BTW if you need more help with this.

thanks a lot for the support! I normally try to stay away from slack

@gdanov gdanov closed this as completed May 26, 2020
@bhauman
Copy link
Owner

bhauman commented May 26, 2020

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

Apparently there is another bug around this in CLJS, so thanks for helping find it. It seems that what you specified should have worked.

@bhauman
Copy link
Owner

bhauman commented May 26, 2020

clojurescript 1.10.773 fixes your issues

@gdanov
Copy link
Author

gdanov commented May 28, 2020

Thanks, tested it (incl. several permutations I typically try when things are broken) and everything works as expected. Fells very luxurious :)

I spent little time thinking and what surprises me is that I hit this bug first. This shows I'm using set-up that's not common and that's pretty big surprise (to me). I try not to be early adopter of build tools. Couple thoughts that may be useful, in random order:

  • coming from react-scripts, first I'm used to consume npm modules, second all the processing involved is smoothly working black box. I expected figwheel to give me similar experience (which it does now with :target :bundle)
    • I hit this bug due to npm module of a browser lib that's not proper web bundle (has require() in the minimized version). This broke the build so I remembered I read recently about :target :build. I must've been lucky with the npm deps I used before this not to hit similar case
  • if my use of npm-modules for web dev is fairly exotic, what's the default then? In the (excellent) figwheel-main tutorial consuming other modules (npm or not) is not discussed

I'd put some tutorial how to do this already to help the community if I felt confident I know what I'm doing but this is not how I feel yet. Btw this is indicative of the dev ex. Once again — not ranting or complaining.

P.S. not to come across as rude rejecting to talk on slack — I prefer tickets to slack because they are indexed so someone with my problem would find solution easier. For this (and pretty much any serious work) slack is broken (to me).

@bhauman
Copy link
Owner

bhauman commented May 29, 2020

@gdanov I think most if this chalks up to the fact that the :bundle target is bleeding edge right now. Very few people are using it yet. Those were really bad bugs and they shouldn't have been in there. I'm trying to document this stuff here https://figwheel.org/docs/npm.html

NPM integration is going down a better path now and I'm hoping these problems will be a thing of the past.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants