bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 210 forks source link

Dependencies in REPL #723

Closed lambdaofgod closed 5 years ago

lambdaofgod commented 5 years ago

First of all, thank you guys for your great work!

I want to use figwheel to experiment with external js library (tensorflow.js). How to do it?

What I tried:

I tried running clojure -A:fig:build, which runs a REPL. But I can't import js/tf in it - it tells me that tf isn't defined (also when I try to require it, (:require [cljsjs.tfjs]) throws ReferenceError: cljsjs is not defined That's weird given that my core.clj seems to import it and doesn't throw any errors:

(ns ^:figwheel-hooks hello-world.core
    (:require [reagent.core] [cljsjs.tfjs]))

(def t (.tensor js/tf (clj->js [1 2 3])))
(defn my-component []
  [:p "My first React component"])
(defn ^:export main []
  (reagent.core/render
    [my-component]
    (.getElementById js/document "app")))
(main)

My `deps.edn

{:deps {org.clojure/clojure       {:mvn/version "1.9.0"}
        org.clojure/clojurescript {:mvn/version "1.10.339"}
        reagent                   {:mvn/version "0.8.1"}
        cljsjs/tfjs {:mvn/version "0.12.0-0"}}
 :paths ["src" "resources"]
 :aliases {:fig {:extra-deps
                 {
                  com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}
                  com.bhauman/figwheel-main       {:mvn/version "0.1.9"}
                  cljsjs/tfjs {:mvn/version "0.12.0-0"}
                  }
                 :extra-paths ["target" "test" "resources"]}
           :build {:main-opts ["-m" "figwheel.main" "-b" "dev" "-r"]}
           }
 }

What's happening? Does my core.clj file actually run? If not, how to make it run?

lambdaofgod commented 5 years ago

Nevermind, found it - I needed to read about imports, for example from this stackoverflow answer