简体   繁体   中英

Can't get browser repl to work from chestnut template (figwheel, weasel)

I try to get started with ClojureScript using the chestnut leiningen template which combines piggyback, figwheel and weasel. After upgrading my leiningen installation to 2.5.0, I can start the clojure repl, but after issuing the recommended run and browser-repl commands, I run into a cryptic error. There seems to be a core.async issue as well, which I don't know whether it's related.

chestnut-borked.server=> (run)
2014-10-07 12:38:06.506:INFO:oejs.Server:jetty-7.6.13.v20130916
2014-10-07 12:38:06.545:INFO:oejs.AbstractConnector:Started SelectChannelConnector@0.0.0.0:10555
Starting figwheel.
Starting web server on port 10555 .
#<Server org.eclipse.jetty.server.Server@6cdd377c>
Compiling ClojureScript.
Figwheel: Starting server at http://localhost:3449
Figwheel: Serving files from '(dev-resources|resources)/public'
Compiling "resources/public/js/app.js" from ["src/cljs"]...
WARNING: Use of undeclared Var cljs.core.async/do-alts at line 62 file:/home/schauer /.m2/repository/org/clojure/core.async/0.1.278.0-76b25b-alpha/core.async-0.1.278.0-76b25b-alpha.jar!/cljs/core/async/impl/ioc_helpers.cljs
WARNING: Bad method signature in protocol implementation impl/Handler lock-id at line 214 file:/home/schauer/.m2/repository/org/clojure/core.async/0.1.278.0-76b25b-alpha/core.async-0.1.278.0-76b25b-alpha.jar!/cljs/core/async.cljs
WARNING: Use of undeclared Var cljs.core.async.impl.protocols/lock-id at line 217 file:/home/schauer/.m2/repository/org/clojure/core.async/0.1.278.0-76b25b-alpha/core.async-0.1.278.0-76b25b-alpha.jar!/cljs/core/async.cljs
WARNING: Use of undeclared Var chestnut-borked.dev/put! at line 14 src/cljs/chestnut_borked/dev.cljs
[... some warnings removed after first answer ...]
WARNING: Bad method signature in protocol implementation impl/Handler lock-id at line 214 resources/public/js/out/cljs/core/async.cljs
WARNING: Use of undeclared Var cljs.core.async.impl.protocols/lock-id at line 217 resources/public/js/out/cljs/core/async.cljs
Successfully compiled "resources/public/js/app.js" in 21.377 seconds.
notifying browser that file changed:  /js/app.js
notifying browser that file changed:  /js/out/goog/deps.js
notifying browser that file changed:  /js/out/chestnut_borked/core.js
notifying browser that file changed:  /js/out/chestnut_borked/dev.js

Besides from the warnings, so far, so good -- Jetty seems to have started successfully. However, when I try to start the browser-repl, I run into an error and the connection seems to be broken:

chestnut-borked.server=> (browser-repl)
WARNING: Bad method signature in protocol implementation impl/Handler lock-id at line 214 file:/home/schauer/.m2/repository/org/clojure/core.async/0.1.278.0-76b25b-alpha/core.async-0.1.278.0-76b25b-alpha.jar!/cljs/core/async.cljs
ArityException Wrong number of args (0) passed to: compiler/with-core-cljs  clojure.lang.AFn.throwArity (AFn.java:429)

chestnut-borked.server=> (browser-repl)
java.io.IOException: No client connected to Websocket
  at weasel.repl.server$send_BANG_.invoke(server.clj:25)
  at weasel.repl.websocket$send_for_eval_BANG_.invoke(websocket.clj:130)
  at weasel.repl.websocket$websocket_eval.invoke(websocket.clj:109)
  at weasel.repl.websocket.WebsocketEnv._evaluate(websocket.clj:34)
  at cljs.repl$evaluate_form.invoke(repl.clj:113)
  at cemerick.piggieback$cljs_eval$fn__5152.invoke(piggieback.clj:115)
  at clojure.lang.AFn.applyToHelper(AFn.java:152)
  at clojure.lang.AFn.applyTo(AFn.java:144)
  [...]

UPDATE: After the input from lnmx, it's becoming clear that weasel isn't functioning properly. If I take a look at the JS elements that the browser sees, the dev script apparently doesn't get loaded and neither is the repl.js from weasel, although there are goog.addDependency calls for them in app.js .

Chestnut 0.5.0 has been released now. It contains an updated ClojureScript which should fix the issue with Weasel (the browser-connected REPL), as well as several other improvements.

I had some success with chestnut 0.5.0, but some changes were needed. I am new to Clojure so I may be missing something -- anyway, here's what I found:

It looks like the README file for chestnut describes the usage of version 0.5.0, but that version is not available on clojars as of today.

So, per the README, I installed from a local copy:

git clone https://github.com/plexus/chestnut.git
cd chestnut
lein install

...and created a new project:

lein new chestnut tree

Attempting to compile the cljs with lein cljsbuild once produced the Bad method signature warning related to lock-id . So, I started by adding the latest core.async to project.clj under :dependencies

[org.clojure/core.async "0.1.346.0-17112a-alpha"]

Then there were some errors related to undefined core.async functions, so I fixed the requires in src/cljs/tree/core.cljs :

(ns tree.core
    (:require [tree.dev :refer [is-dev?]]
              [cljs.core.async :refer [chan <!]]
              [om.core :as om :include-macros true]
              [om.dom :as dom :include-macros true])
    (:require-macros [cljs.core.async.macros :refer [go alt!]]))

and src/cljs/tree/dev.cljs :

(ns tree.dev
    (:require [figwheel.client :as figwheel :include-macros true]
              [cljs.core.async :refer [put!]]
              [weasel.repl :as weasel]))

The next issue is that tree.dev needs a reference to the re-render-ch owned by tree.core . So I wrapped the "dev mode" setup into a function called from tree.core ( src/cljs/tree/core.cljs ):

(defonce re-render-ch (chan))

(when is-dev?
  (tree.dev/setup re-render-ch))

...and implemented in tree.dev ( src/cljs/tree/dev.cljs ):

(def is-dev? (.contains (.. js/document -body -classList) "is-dev"))

(defn setup [re-render-ch]
  (when is-dev?
    (enable-console-print!)

    (figwheel/watch-and-reload
     :websocket-url "ws://localhost:3449/figwheel-ws"
     :jsload-callback (fn []
                        (println "reloaded")
                        (put! re-render-ch true)))

    (weasel/connect "ws://localhost:9001" :verbose true)))

With those changes, I can start lein repl , (run) and (browser-repl) OK.

During (run) I get this error:

ArityException Wrong number of args (0) passed to: compiler/with-core-cljs

(not sure where this is coming from). However, if I edit tree/src/cljs/tree/core.cljs and add

(reset! app-state {:text "Hello There?"})

the change is compiled automatically and shows up in the browser shortly after I save the file.

Per the comment, this still doesn't fix the browser-repl. For that I had to get a local copy of weasel , and hack src/clj/weasel/repl/websocket.clj ~line 88:

-  (cmp/with-core-cljs)
+  (cmp/with-core-cljs {} (fn [] (println "foo")))

It seems to be related to an API change in the cljs compiler. With that, I can (browser-repl) without any warnings, and (do (js/alert "Hello world!") 42) produces an alert in the browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM