简体   繁体   English

无法从栗子模板(figwheel,鼬鼠)获得浏览器副本的支持

[英]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. 我尝试使用结合了背back式,无头轮式和鼬鼠式的栗子leiningen模板开始使用ClojureScript。 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. 将leiningen安装升级到2.5.0之后,我可以启动clojure repl,但是在发出建议的runbrowser-repl命令之后,我遇到了一个隐秘的错误。 There seems to be a core.async issue as well, which I don't know whether it's related. 似乎也有一个core.async问题,我不知道它是否相关。

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: 但是,当我尝试启动浏览器-repl时,遇到错误,并且连接似乎断开了:

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. 更新:从lnmx输入后,很明显黄鼠狼不能正常工作。 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 . 如果我看一下浏览器看到的JS元素,虽然app.jsgoog.addDependency调用,但显然不会加载dev脚本,weasel的repl.js也不会加载。

Chestnut 0.5.0 has been released now. 栗子0.5.0现在已经发布。 It contains an updated ClojureScript which should fix the issue with Weasel (the browser-connected REPL), as well as several other improvements. 它包含一个更新的ClojureScript,可以解决Weasel(与浏览器相连的REPL)的问题以及其他一些改进。

I had some success with chestnut 0.5.0, but some changes were needed. 我在栗子0.5.0上取得了一些成功,但需要进行一些更改。 I am new to Clojure so I may be missing something -- anyway, here's what I found: 我是Clojure的新手,所以我可能会缺少一些东西-无论如何,这是我发现的内容:

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. 栗子的README文件似乎描述了版本0.5.0的用法,但是该版本到目前为止clojars中不可用。

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 . 尝试使用lein cljsbuild once编译lein cljsbuild once产生了与lock-id相关的Bad method signature警告。 So, I started by adding the latest core.async to project.clj under :dependencies 因此,我首先在:dependencies下将最新的core.async添加到project.clj

[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 : 然后有相关的不确定core.async功能的一些错误,所以我固定requiressrc/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 : 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 . 下一个问题是tree.dev需要对tree.core拥有的re-render-chtree.core So I wrapped the "dev mode" setup into a function called from tree.core ( src/cljs/tree/core.cljs ): 因此,我将“开发模式”设置包装到一个从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 ): ...并在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. 通过这些更改,我可以启动lein repl(run)(browser-repl)确定。

During (run) I get this error: (run)期间,出现此错误:

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 但是,如果我编辑tree/src/cljs/tree/core.cljs并添加

(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: 为此,我必须获取weasel的本地副本,并破解src/clj/weasel/repl/websocket.clj第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. 它似乎与cljs编译器中的API更改有关。 With that, I can (browser-repl) without any warnings, and (do (js/alert "Hello world!") 42) produces an alert in the browser. 这样,我可以(browser-repl)没有任何警告,并且(do (js/alert "Hello world!") 42)在浏览器中产生警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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