bhauman / figwheel-main

Figwheel Main provides tooling for developing ClojureScript applications
https://figwheel.org
Eclipse Public License 1.0
640 stars 93 forks source link

Don't pass :bundle-cmd to compiler-env #317

Closed jaimesangcap closed 2 years ago

jaimesangcap commented 2 years ago

Hi! Thank you for building this awesome tool! We just happily migrated our tooling to figwheel-main. However on our second project, we are having weird issue. When running lein fig -- -b dev -r (:auto-bundle :webpack or passing :target :bundle + :bundle-cmd explicitly), the app compiles fine the first time, but throws error when it detect changes and tries to recompile.

^{:ring-server-options {:port 3450}
  :watch-dirs          ["src" "test"]
  :css-dirs            ["resources/public/css"]
  :open-url            false
  :clean-outputs       true
  :auto-testing        true}
{:main                 dnyarri.core
 :optimizations        :none
 :target               :bundle
:bundle-cmd {:default ["npx" "webpack" "--mode=production" "--entry" :output-to
                         "--output-path" :final-output-dir
                         "--output-filename" :final-output-filename]}
 :aot-cache            false
 :cache-analysis       false
 :parallel-build       true
 :output-to            "resources/public/js/compiled/app.js"
 :output-dir           "resources/public/js/compiled"
 :asset-path           "/js/compiled"
 :source-map-timestamp true
 :infer-externs        true
 :language-in           :es-next
 :preloads             [devtools.preload
                        day8.re-frame-10x.preload]
 :foreign-libs         [{:file        "src"
                         :module-type :es6}
                        {:file     "node_modules/@sentry/tracing/build/bundle.tracing.min.js"
                         :provides ["sentry.with.tracing"]}]}

Here is the error:

[Figwheel] Failed to compile build dev in 8.398 seconds.
[Figwheel:WARNING] Compile Exception: No value supplied for key: :final-output-filename
[Figwheel:SEVERE] java.lang.IllegalArgumentException: No value supplied for key: :final-output-filename
[Figwheel:FINE] {:via
 [{:type clojure.lang.ExceptionInfo,
   :message ":build-cmd :none failed",
   :data
   {:cmd
    ["npx"
     "webpack"
     "--mode=development"
     "--entry"
     :output-to
     "--output-path"
     :final-output-dir
     "--output-filename"
     :final-output-filename]},
   :at
   [cljs.closure$run_bundle_cmd$fn__6335 invoke "closure.clj" 3058]}
  {:type java.lang.IllegalArgumentException,
   :message "No value supplied for key: :final-output-filename",
   :at
   [clojure.lang.PersistentHashMap
    create
    "PersistentHashMap.java"
    77]}],
 :trace
 [[clojure.lang.PersistentHashMap create "PersistentHashMap.java" 77]
  [clojure.core$hash_map invokeStatic "core.clj" 389]
  [clojure.core$hash_map doInvoke "core.clj" 381]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.java.shell$parse_args invokeStatic "shell.clj" 47]
  [clojure.java.shell$sh invokeStatic "shell.clj" 79]
  [clojure.java.shell$sh doInvoke "shell.clj" 79]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$apply invoke "core.clj" 662]
  [cljs.closure$run_bundle_cmd$fn__6335 invoke "closure.clj" 3055]
  [cljs.closure$run_bundle_cmd invokeStatic "closure.clj" 3054]
  [cljs.closure$run_bundle_cmd invoke "closure.clj" 3050]
  [cljs.closure$build invokeStatic "closure.clj" 3227]
  [cljs.closure$build invoke "closure.clj" 3065]
  [figwheel.core$eval3722$build__3724 doInvoke "core.cljc" 869]
  [clojure.lang.RestFn applyTo "RestFn.java" 146]
  [clojure.core$apply invokeStatic "core.clj" 671]
  [clojure.core$apply invoke "core.clj" 662]
  [figwheel.main$wrap_with_build_logging$fn__5274$fn__5280
   invoke
   "main.cljc"
   187]
  [figwheel.main$wrap_with_build_logging$fn__5274
   doInvoke
   "main.cljc"
   183]
  [clojure.lang.RestFn applyTo "RestFn.java" 146]
  [clojure.core$apply invokeStatic "core.clj" 673]
  [clojure.core$apply invoke "core.clj" 662]
  [figwheel.main$wrap_with_bundling$fn__5270 doInvoke "main.cljc" 154]
  [clojure.lang.RestFn applyTo "RestFn.java" 146]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$apply invoke "core.clj" 662]
  [figwheel.main$wrap_with_build_hooks$fn__5293
   doInvoke
   "main.cljc"
   210]
  [clojure.lang.RestFn applyTo "RestFn.java" 137]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$apply invoke "core.clj" 662]
  [figwheel.main$wrap_with_compiler_passes$fn__5296
   doInvoke
   "main.cljc"
   219]
  [clojure.lang.RestFn invoke "RestFn.java" 482]
  [figwheel.main$watch_build$fn__5304 invoke "main.cljc" 247]
  [figwheel.main$watch_build$fn__5308 invoke "main.cljc" 297]
  [clojure.lang.AFn applyToHelper "AFn.java" 154]
  [clojure.lang.AFn applyTo "AFn.java" 144]
  [clojure.core$apply invokeStatic "core.clj" 667]
  [clojure.core$with_bindings_STAR_ invokeStatic "core.clj" 1977]
  [clojure.core$with_bindings_STAR_ doInvoke "core.clj" 1977]
  [clojure.lang.RestFn applyTo "RestFn.java" 142]
  [clojure.core$apply invokeStatic "core.clj" 671]
  [clojure.core$bound_fn_STAR_$fn__5767 doInvoke "core.clj" 2007]
  [clojure.lang.RestFn invoke "RestFn.java" 408]
  [figwheel.main.watching$throttle$fn__4155$fn__4158
   invoke
   "watching.clj"
   62]
  [clojure.core$binding_conveyor_fn$fn__5772 invoke "core.clj" 2034]
  [clojure.lang.AFn call "AFn.java" 18]
  [java.util.concurrent.FutureTask run "FutureTask.java" 264]
  [java.util.concurrent.ThreadPoolExecutor
   runWorker
   "ThreadPoolExecutor.java"
   1128]
  [java.util.concurrent.ThreadPoolExecutor$Worker
   run
   "ThreadPoolExecutor.java"
   628]
  [java.lang.Thread run "Thread.java" 834]],
 :cause "No value supplied for key: :final-output-filename"}

After some debugging, it seems like the cljs.closure/build picks up options from the compiler-env here, which will then run the bundle-cmd here.

This will cause an error since the value of :bundle-cmd is a template

:bundle-cmd
 {:none
  [:npx-cmd
   "webpack"
   "--mode=development"
   "--entry"
   :output-to
   "--output-path"
   :final-output-dir
   "--output-filename"
   :final-output-filename],
  :default
  [:npx-cmd
   "webpack"
   "--mode=production"
   "--entry"
   :output-to
   "--output-path"
   :final-output-dir
   "--output-filename"
   :final-output-filename]}
Screen Shot 2022-04-14 at 12 49 49 AM

Proposed solution

Since figwheel already handles running the :bundle-cmd, it's unnecessary to pass that option again to cljs compiler to re-run the command. I created the PR https://github.com/bhauman/figwheel-main/pull/316

Or alternatively, fill-in the bundle-cmd template with actual value.

timothypratley commented 2 years ago

Hi @jaimesangcap :wave:

It looks to me like you are running into this behavior by specifying the :bundle-cmd template in the ClojureScript configuration instead of the Figwheel configuration. If this is the case, you shouldn't do that. My understanding is that Figwheel doesn't run the bundler, it just takes care of passing a sensible :bundle-cmd to the ClojureScript compiler. There are many ways to control the bundler command, so it can be a bit confusing! Could you please confirm that you are specifying the template in figwheel options only (e.g.: metadata on the compiler options)? If you could post more details on your configuration or a minimal example that would be helpful (thanks for posting the key/value, but it is necessary to know where that is being placed).

jaimesangcap commented 2 years ago

Hi @timothypratley , thanks for your reply. I've tried putting it in metadata.

^{:ring-server-options {:port 3450}
  :watch-dirs          ["src" "test"]
  :css-dirs            ["resources/public/css"]
  :open-url            false
  :clean-outputs       true
  :auto-testing        true
  :bundle-cmd {:default ["npx" "webpack" "--mode=production" "--entry" :output-to
                         "--output-path" :final-output-dir
                         "--output-filename" :final-output-filename]}}
{:main                 dnyarri.core
 :optimizations        :none
 :target               :bundle
 :aot-cache            false
 :cache-analysis       false
 :parallel-build       true
 :output-to            "resources/public/js/compiled/app.js"
 :output-dir           "resources/public/js/compiled"
 :asset-path           "/js/compiled"
 :source-map-timestamp true
 :infer-externs        true
 :language-in           :es-next
 :preloads             [devtools.preload
                        day8.re-frame-10x.preload]
 :foreign-libs         [{:file        "src"
                         :module-type :es6}
                        {:file     "node_modules/@sentry/tracing/build/bundle.tracing.min.js"
                         :provides ["sentry.with.tracing"]}]}

But figwheel-main said it's not a valid option

(fw/start "dev")
Execution error (ExceptionInfo) at figwheel.main.schema.core/validate-config! (core.clj:104).
Configuration error in build options meta data: dev.cljs.edn
-- Unknown map key ----------------

  {:ring-server-options ...,
   :watch-dirs ...,
   :css-dirs ...,
   :open-url ...,
   :clean-outputs ...,
   :auto-testing ...,
   :bundle-cmd ...}
   ^^^^^^^^^^^

should be one of

  :ring-stack, :client-log-level, :post-build-hooks, :validate-config, :ring-handler, :bundle-once, :clean-outputs, :repl-eval-timeout, :pprint-config, :log-level, :cljsjs-resources, :ring-server-options, :auto-bundle, :broadcast, :log-file, :bundle-freq, :reload-dependents, :mode, :helpful-classpaths, :connect-url, :extra-main-files, :inspect-node, :launch-js, :launch-node, :react-native:react-native, :auto-testing, :open-url-wait-ms, :watch-dirs, :react-native-auto-refresh, :pre-build-hooks, :ansi-color-output, :rebel-readline, :ssl-valid-hosts, :ring-server, :broadcast-reload, :figwheel-core, :client-print-to, :final-output-to, :cljs-devtools, :open-file-command, :build-inputs, :wait-time-ms, :validate-cli, :ring-stack-options, :target-dir, :hot-reload-cljs, :npm, :node-command, :load-warninged-code, :log-syntax-error-style, :reload-clj-files, :css-dirs, :open-url, :use-ssl

-------------------------
Detected 1 error
timothypratley commented 2 years ago

Ah right, I understand now. Thank you for clarifying. I'll respond further on the PR.