Fork me on GitHub
#figwheel-main
<
2018-09-08
>
dazld13:09:39

hey everyone! I’m starting out with cljs (done a fair amount of clojure though), and hitting a wall when trying to load a foreign lib

dazld13:09:02

No such namespace: hdom, could not locate hdom.cljs, hdom.cljc, or JavaScript source providing "hdom" in file src/hello_hdom/core.cljs

  1  (ns ^:figwheel-hooks hello-hdom.core
                                ^---
  2    (:require
  3     [goog.dom :as gdom]
  4     [hdom :as hdom]))
  5
  6  (println hdom)

dazld13:09:16

the config … looks right?

richiardiandrea17:09:21

@dazld did you include hdom in your :npm-deps ? Usually it is in dev.cljs.edn. Note also that this is not the recommended way of importing js anymore as cljs core suggests to use webpack

dazld18:09:00

that was the first thing I tried, but think it was just in the wrong place

dazld18:09:38

however - all is ok, as got some great pointers from people on hash clojurescript

dazld18:09:25

could you point me to where webpack is the current suggestion?

richiardiandrea18:09:37

I would also recommend checking http://shadow-cljs.org/ as a layer on top of the compiler (like figwheel-main, but more npm friendly)

dazld18:09:11

thanks, that's interesting

dazld18:09:26

picking apart what each bit is doing especially

dazld18:09:23

wonder if webpack is strictly necessary there, for example...

richiardiandrea18:09:25

Well interesting but used to be better to have one tool only IMHO. Now non-JS users need to learn webpack - my 2c

pesterhazy18:09:51

@dazld check this demo repository for rationale and howto aspects of using webpack with cljs: https://github.com/pesterhazy/cljs-spa-example

pesterhazy18:09:57

(hi Dan btw!)

dazld18:09:28

and cool, will do

eval202019:09:10

@pesterhazy just got that project working with the latest CIDER: very nice 👌, thanks!

pesterhazy19:09:20

@eval2020 cool! did you have to change the configuration in any way?

eval202019:09:26

while fiddling around, I upgraded fw-main in deps.edn, but not necessary I assume

eval202019:09:51

one tricky thing: after selecting the ClojureScript REPL type it asks Select figwheel-main build (e.g. :dev):. You should not accept the default (`:dev`), but answer dev

neural15:09:59

@eval2020 after a week trying to hack emacs/cider/figwheel-main trying new fresh systems.... and suddenly this cracks the sky!!!

👍 1
pesterhazy19:09:24

did you have to add anything to deps.edn?

eval202019:09:34

M-x cider-jack-in-cljs and go

pesterhazy19:09:03

cool, maybe I should add that to the README

eval202019:09:36

just did a fresh clone to reproduce: - run ./script/dev - kill this process after bundle got build - M-x cider-jack-in-cljs - select figwheel-main - Select figwheel-main build, type dev - visit http://localhost:9333 - cljs prompt appears

eval202019:09:54

if script/dev could start an nrepl-server, just a cider-connect would suffice - not sure if that’s possible

eval202020:09:24

possible as an option to figwheel-main

pesterhazy20:09:09

yeah I think cider preforms some magic to add in the necessary nrepl middleware

eval202020:09:23

*Messages* shows it starts

/usr/local/bin/clojure -Sdeps '{:deps {org.clojure/tools.nrepl {:mvn/version "0.2.13"} cider/piggieback {:mvn/version "0.3.9"} cider/cider-nrepl {:mvn/version "0.18.0"}}}' \
  -e '(require (quote cider-nrepl.main)) (cider-nrepl.main/init ["cider.nrepl/cider-middleware", "cider.piggieback/wrap-cljs-repl"])'

pesterhazy20:09:01

so it runs -e to bootstrap nrepl, cider and piggieback

pesterhazy20:09:31

and then you can still add -m figwheel.main at the end of the command line?

pesterhazy20:09:57

or does Cider initialize figwheel manually?

eval202020:09:57

the fw build you selected starts at the clj-repl

gdanov10:09:50

@pesterhazy it does not add -m (even though that would work) but you have to start figwheel in the resulting clj repl yourself. can be automated by defining your own type of cljs repl

gdanov10:09:08

or you can customize the cider's jack options to add the -m. but I guess that would give you nothing valuable as fig would run headless and you still need to start cljs-repl in the clj repl

pesterhazy10:09:46

thanks for the explanation

gdanov11:09:06

thanks for your sample app

pesterhazy20:09:22

that's pretty clean, but not sure if other repl clients can do the same

thiru20:09:58

Is it possible to set a custom initial namespace with figwheel-main? I.e. rather than cljs.user

gdanov21:09:26

re CIDER interop. After some experiments I ended up with simple set-up to start fig manually and then cider-connect: deps.edn:

{:paths ["src/cljs" "target"]

 :deps {org.clojure/clojure       {:mvn/version "1.9.0"}
        org.clojure/clojurescript {:mvn/version "1.10.339"}}

 :aliases {:fig {:extra-deps {cider/cider-nrepl {:mvn/version "0.18.0"}
                              cider/piggieback  {:mvn/version "0.3.9"}

                              com.bhauman/figwheel-main       {:mvn/version "0.1.9"}
                              com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}}}

           :bs {:extra-paths ["."]
                :main-opts   ["-m bootstrap"]}}}
bootstrap.clj
(ns bootstrap
  (:require [figwheel.main.api]
            [cider-nrepl.main :as cider]))

(defn -main [& args]

  (cider/init ["cider.nrepl/cider-middleware"])
  (println "*********************")

  (figwheel.main.api/start "dev"))
then just run in term >clj -A:fig:bs and then cider-connect. Once in clojure repl do
(figwheel.main.api/cljs-repl "dev")
andvantage of this approach is you can run it on vanilla CIDER and won't need to customize it.

👍 2
gdanov21:09:34

if you prefer to customize cider this is one example I found which might help https://github.com/arichiardi/figwheel-main-cider/blob/master/.dir-locals.el

richiardiandrea21:09:53

I should actually fix the keyword issue, it should work with both. I might have introduced a regression in cider

eval202022:09:30

@richiardiandrea currently on mobile but it might just work. What I assumed is that by just pressing enter, :dev would be used as default. But it’s given as an example.

Yehonathan Sharvit23:09:08

Is it possible to remotely connect to the Figwheel REPL (either nrepl or socket repl)

Yehonathan Sharvit23:09:22

I’d like to connect Cursive to the Figwheel REPL