reagent-project / reagent-template

A Leiningen template for projects using Reagent.
MIT License
394 stars 55 forks source link

lein repl not working when template is used wiht +cljx #42

Closed matystl closed 9 years ago

matystl commented 9 years ago

I am new to clojure and clojurescript and i have small problems/questions regarding this template.

I am able to make this temlate working with command "lein figwheel" but "lein repl" is not working. In docs it say that (browser-repl) is for optional development tools and i don't understand what optional development tools it actualy support because as i run lein figwheel(and open website) i get repl from which i can iteract with code running in browser. So do i have to run (browser-repl) manualy?

My second problem is i have no idea how to reload server code. As i change something in src/clj/handler.clj only way to reload server i know now is to restart lein figwheel. Probably there's better way and it would be great to mension it in documentation. Best would be to have same autoreload with server code as we have right now with client code but not sure if that is possible.

My third problem is automatic reloading of common code(cljx). I manage to have it live reload in client by running in separete terminal "lein cljx auto" but it would be nice if it would be integrated in some leinigen task together with start of figwheel.

Steps to reproduce problem with lein repl:

terminal_1> lein new reagent bug1 +cljx
terminal_1> cd bug1
terminal_1> lein cljx
terminal_1> lein figwheel
....
This is working ok

terminal_2> lein repl
Rewriting src/cljx to target/generated/clj (clj) with features #{clj} and 0 transformations.
Rewriting src/cljx to target/generated/cljs (cljs) with features #{cljs} and 1 transformations.
Error loading cljx.repl-middleware: Could not locate cljx/repl_middleware__init.class or cljx/repl_middleware.clj on classpath: 
Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: cljx.repl-middleware/wrap-cljx in this context, compiling:(/tmp/form-init8680695657060285587.clj:1:2987)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6651)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.access$100(Compiler.java:38)
    at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6050)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
    at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5217)
    at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3846)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.eval(Compiler.java:6700)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.load(Compiler.java:7130)
    at clojure.lang.Compiler.loadFile(Compiler.java:7086)
    at clojure.main$load_script.invoke(main.clj:274)
    at clojure.main$init_opt.invoke(main.clj:279)
    at clojure.main$initialize.invoke(main.clj:307)
    at clojure.main$null_opt.invoke(main.clj:342)
    at clojure.main$main.doInvoke(main.clj:420)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: cljx.repl-middleware/wrap-cljx in this context
    at clojure.lang.Util.runtimeException(Util.java:221)
    at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:659)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
    ... 34 more
yogthos commented 9 years ago

So, if you're runing lein figwheel then you do not need to run (browser-repl) manually. The REPL workflow is for using something like Emacs where you would start up a REPL and and then hook up the browser REPL from there.

I recommend not worrying about it too much at this point. When figwheel starts up it will automatically reload any changes in the browser for you already.

For the server side you don't have to do anything special for the code to reload. When you run lein ring server it already runs in dev mode and watches for changes in the source.

Finally, I don't believe there is a separate way to reload cljx. I know some people use boot that lets you do some fancier workflows than lein, but I haven't used it myself.

matystl commented 9 years ago

Is it ok to close this issue? You answer most of my question and currently my workflow was to run in 3 consols commands lein cljx auto lein ring server lein figwheel and everything was working as should. But lein repl is still not working(checked at time of writing comment). So it would be good to closed this after lein repl will be working or at least write somehing about it in readme.

yogthos commented 9 years ago

Ah ok, I missed the lein repl part re-reading the issue. I recently made a similar fix for Luminus, so I think I could add something similar here as well.

yogthos commented 9 years ago

@matystl I just checked in a fix for the REPL, could you test to confirm that it works as expected?

matystl commented 9 years ago

@yogthos just checked it and it doesnt look like your latest commit v0.6.6 is live on https://clojars.org/reagent/lein-template can i check it from git repositary directly? If yes than what i need to write instead of lein new reagent bug +cljx?

yogthos commented 9 years ago

It's not pushed out yet, I want to test it to make sure it fixes the issue. :) And yeah you'd just check it out and then run lein install to install it in the local repo

matystl commented 9 years ago

cloned repo and install it and checked that it have latest commit. But still not working now with another error:

maty@maty-linux ~/vacuumlabs/clojure/bug4 $ lein repl
Rewriting src/cljx to target/generated/clj (clj) with features #{clj} and 0 transformations.
Rewriting src/cljx to target/generated/cljs (cljs) with features #{cljs} and 1 transformations.
#<CompilerException java.io.FileNotFoundException: Could not locate ring/server/standalone__init.class or ring/server/standalone.clj on classpath: , compiling:(bug4/repl.clj:1:1)>
Error loading cljx.repl-middleware: Could not locate cljx/repl_middleware__init.class or cljx/repl_middleware.clj on classpath: 
Exception in thread "main" java.lang.RuntimeException: Unable to resolve var: cljx.repl-middleware/wrap-cljx in this context, compiling:(/tmp/form-init1919806377048152094.clj:1:2991)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6651)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3719)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6646)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.access$100(Compiler.java:38)
    at clojure.lang.Compiler$LetExpr$Parser.parse(Compiler.java:6050)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.analyze(Compiler.java:6406)
    at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5782)
    at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5217)
    at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3846)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6642)
    at clojure.lang.Compiler.analyze(Compiler.java:6445)
    at clojure.lang.Compiler.eval(Compiler.java:6700)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.eval(Compiler.java:6693)
    at clojure.lang.Compiler.load(Compiler.java:7130)
    at clojure.lang.Compiler.loadFile(Compiler.java:7086)
    at clojure.main$load_script.invoke(main.clj:274)
    at clojure.main$init_opt.invoke(main.clj:279)
    at clojure.main$initialize.invoke(main.clj:307)
    at clojure.main$null_opt.invoke(main.clj:342)
    at clojure.main$main.doInvoke(main.clj:420)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:383)
    at clojure.lang.AFn.applyToHelper(AFn.java:156)
    at clojure.lang.Var.applyTo(Var.java:700)
    at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: Unable to resolve var: cljx.repl-middleware/wrap-cljx in this context
    at clojure.lang.Util.runtimeException(Util.java:221)
    at clojure.lang.Compiler$TheVarExpr$Parser.parse(Compiler.java:659)
    at clojure.lang.Compiler.analyzeSeq(Compiler.java:6644)
    ... 34 more
REPL server launch timed out.
yogthos commented 9 years ago

looks like it might need additional dependencies for repl/cljx

yogthos commented 9 years ago

OK, so figured out the missing dependency and everything should be working as expected now. I pushed out the latest to Clojars, let me know if there's any other issues.

matystl commented 9 years ago

Nice it's working without exceptions. Last thing is that now you have to swich namespaces when you want to run (browser-repl). It would be nice to mension it in readme. Also nice would be to describe what (start-server) and (stop-server) are for or better how is prefered way to start project for people new to clojure. Thanks for help

yogthos commented 9 years ago

Right, I just pushed out a new version that references the dev ns in the repl ns so that you don't have to switch namespaces. I'll update the docs with the server commands. Sounds like we got this one resolved. :)