我写了一些测试,我发现:
在repl中只需要与我编译的clojurescript相关的名称空间。 在repl中不需要任何编译的clojurescript没有引用的命名空间。
这是REPL
的限制吗?或者这里有什么问题?
当我需要没有被任何已编译的clojurescript引用的命名空间时,我收到错误:
cljs.user> (require 'cljsjs.d3)
711cljs.core._STAR_print_namespace_maps_STAR_ = true
712Loading: (goog)
713Loading: (cljsjs.d3)
714goog.addDependency("base.js", [], []);
715goog.addDependency("../cljsjs/d3/development/d3.inc.js", [], []);
716
717goog.require('cljsjs.d3');
718null;
719
720"Error evaluating:" (require (quote cljsjs.d3)) :as "goog.require('cljsjs.d3');\nnull;\n"
721Error: goog.require could not find: cljsjs.d3
722Failed to canonicalize stacktrace
723clojure.lang.ExceptionInfo: Could not relativize URL http://192.168.124.5:9000/goog/base.js {:type :parse-stacktrace, :reason :relativize-url}
724 at clojure.core$ex_info.invokeStatic(core.clj:4617)
725 at clojure.core$ex_info.invoke(core.clj:4617)
726 at cljs.stacktrace$parse_file.invokeStatic(stacktrace.cljc:104)
727 at cljs.stacktrace$parse_file.invoke(stacktrace.cljc:81)
728 at cljs.stacktrace$chrome_st_el__GT_frame.invokeStatic(stacktrace.cljc:121)
729 at cljs.stacktrace$chrome_st_el__GT_frame.invoke(stacktrace.cljc:111)
730 at cljs.stacktrace$eval9220$fn__9221$fn__9222.invoke(stacktrace.cljc:142)
731 at clojure.core$map$fn__4785.invoke(core.clj:2646)
732 at clojure.lang.LazySeq.sval(LazySeq.java:40)
733 at clojure.lang.LazySeq.seq(LazySeq.java:49)
734 at clojure.lang.RT.seq(RT.java:521)
735 at clojure.core$seq__4357.invokeStatic(core.clj:137)
736 at clojure.core$filter$fn__4812.invoke(core.clj:2700)
737 at clojure.lang.LazySeq.sval(LazySeq.java:40)
738 at clojure.lang.LazySeq.seq(LazySeq.java:49)
739 at clojure.lang.RT.seq(RT.java:521)
740 at clojure.lang.LazilyPersistentVector.create(LazilyPersistentVector.java:44)
741 at clojure.core$vec.invokeStatic(core.clj:377)
742 at clojure.core$vec.invoke(core.clj:367)
743 at cljs.stacktrace$eval9220$fn__9221.invoke(stacktrace.cljc:138)
744 at clojure.lang.MultiFn.invoke(MultiFn.java:243)
745 at cljs.repl.browser.BrowserEnv._parse_stacktrace(browser.clj:281)
746 at cemerick.piggieback$fn__9491.invokeStatic(piggieback.clj:100)
747 at cemerick.piggieback$fn__9491.invoke(piggieback.clj:99)
748 at cljs.repl$eval8750$fn__8751$G__8741__8762.invoke(repl.cljc:147)
749 at cljs.repl$display_error$fn__8901.invoke(repl.cljc:440)
750 at cljs.repl$display_error.invokeStatic(repl.cljc:439)
751 at cljs.repl$display_error.invoke(repl.cljc:428)
752 at cljs.repl$repl_caught.invokeStatic(repl.cljc:753)
753 at cljs.repl$repl_caught.invoke(repl.cljc:744)
754 at cemerick.piggieback$run_cljs_repl$fn__9524.invoke(piggieback.clj:206)
755 at cljs.repl$repl_STAR_$fn__9046$fn__9055.invoke(repl.cljc:927)
756 at cljs.repl$repl_STAR_$fn__9046.invoke(repl.cljc:924)
757 at cljs.compiler$with_core_cljs.invokeStatic(compiler.cljc:1271)
758 at cljs.compiler$with_core_cljs.invoke(compiler.cljc:1260)
759 at cljs.repl$repl_STAR_.invokeStatic(repl.cljc:888)
760 at cljs.repl$repl_STAR_.invoke(repl.cljc:760)
761 at cemerick.piggieback$run_cljs_repl.invokeStatic(piggieback.clj:169)
762 at cemerick.piggieback$run_cljs_repl.invoke(piggieback.clj:155)
763 at clojure.lang.AFn.applyToHelper(AFn.java:171)
764 at clojure.lang.AFn.applyTo(AFn.java:144)
765 at clojure.core$apply.invokeStatic(core.clj:650)
766 at clojure.core$apply.invoke(core.clj:641)
767 at cemerick.piggieback$evaluate.invokeStatic(piggieback.clj:259)
768 at cemerick.piggieback$evaluate.invoke(piggieback.clj:255)
769 at clojure.lang.Var.invoke(Var.java:379)
770 at cemerick.piggieback$wrap_cljs_repl$fn__9548$fn__9550$fn__9551.invoke(piggieback.clj:291)
771 at cemerick.piggieback$enqueue$fn__9534.invoke(piggieback.clj:247)
772 at clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__994.invoke(interruptible_eval.clj:190)
773 at clojure.lang.AFn.run(AFn.java:22)
774 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
775 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
776 at java.lang.Thread.run(Thread.java:748)
777
778Error: goog.require could not find: cljsjs.d3
779 at Object.goog.require [as require__] (http://192.168.124.5:9000/goog/base.js:711:15)
780 at Object.clojure.browser.repl.bootstrap.goog.require (http://192.168.124.5:9000/clojure/browser/repl.js:295:16)
781 at eval (eval at <anonymous> (http://192.168.124.5:9000/clojure/browser/repl.js:106:297), <anonymous>:1:6)
782 at http://192.168.124.5:9000/clojure/browser/repl.js:106:297
783 at clojure$browser$repl$evaluate_javascript (http://192.168.124.5:9000/clojure/browser/repl.js:109:4)
784 at Object.callback (http://192.168.124.5:9000/clojure/browser/repl.js:316:169)
785 at goog.net.xpc.CrossPageChannel.goog.messaging.AbstractChannel.deliver (http://192.168.124.5:9000/goog/messaging/abstractchannel.js:141:13)
786 at goog.net.xpc.CrossPageChannel.xpcDeliver (http://192.168.124.5:9000/goog/net/xpc/crosspagechannel.js:734:12)
787 at Function.goog.net.xpc.NativeMessagingTransport.messageReceived_ (http://192.168.124.5:9000/goog/net/xpc/nativemessagingtransport.js:321:13)
788 at Object.goog.events.fireListener (http://192.168.124.5:9000/goog/events/events.js:744:21)
789cljs.user> (require 'cljsjs.d3)
===========================================
1. Unhandled clojure.lang.ExceptionInfo
6 Error: goog.require could not find: cljsjs.d3
7 {:type :js-eval-exception,
8 :error
9 {:status :exception,
10 :ua-product :chrome,
11 :value "Error: goog.require could not find: cljsjs.d3",
12 :stacktrace
13 "Error: goog.require could not find: cljsjs.d3\n at Object.goog.require [as require__] (http://192.168.124.5:9000/goog/base.js:711:15)\n at Object.clojure.browser.repl.bootstrap.$
14 :form (require 'cljsjs.d3),
15 :js "goog.require('cljsjs.d3');\nnull;\n"}
16
17 core.clj: 4617 clojure.core/ex-info
18 repl.cljc: 527 cljs.repl$evaluate_form/invokeStatic
20 repl.cljc: 452 cljs.repl$evaluate_form/invoke
21 repl.cljc: 625 cljs.repl$eval_cljs/invokeStatic
22 repl.cljc: 618 cljs.repl$eval_cljs/invoke
23 repl.cljc: 880 cljs.repl$repl_STAR_$read_eval_print__9038/invoke
24 repl.cljc: 925 cljs.repl$repl_STAR_$fn__9046$fn__9055/invoke
25 repl.cljc: 924 cljs.repl$repl_STAR_$fn__9046/invoke
26 compiler.cljc: 1271 cljs.compiler$with_core_cljs/invokeStatic
27 compiler.cljc: 1260 cljs.compiler$with_core_cljs/invoke
28 repl.cljc: 888 cljs.repl$repl_STAR_/invokeStatic
29 repl.cljc: 760 cljs.repl$repl_STAR_/invoke
30 piggieback.clj: 169 cemerick.piggieback/run-cljs-repl
31 piggieback.clj: 155 cemerick.piggieback/run-cljs-repl
32 AFn.java: 171 clojure.lang.AFn/applyToHelper
33 AFn.java: 144 clojure.lang.AFn/applyTo
34 core.clj: 650 clojure.core/apply
35 core.clj: 641 clojure.core/apply
36 piggieback.clj: 259 cemerick.piggieback/evaluate
37 piggieback.clj: 255 cemerick.piggieback/evaluate
38 Var.java: 379 clojure.lang.Var/invoke
39 piggieback.clj: 291 cemerick.piggieback/wrap-cljs-repl/fn/fn/fn
40 piggieback.clj: 247 cemerick.piggieback/enqueue/fn
41 AFn.java: 22 clojure.lang.AFn/run
43 ThreadPoolExecutor.java: 1149 java.util.concurrent.ThreadPoolExecutor/runWorker
44 ThreadPoolExecutor.java: 624 java.util.concurrent.ThreadPoolExecutor$Worker/run
45 Thread.java: 748 java.lang.Thread/run
project.clj:
(defproject apps "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:repositories [#_["my.datomic.com" {:url "https://my.datomic.com/repo"
:snapshots false
:username "xfcjscn@gmail.com"
:password "18f81b06-0226-4d59-9060-7e01182a6030"}]]
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/core.async "0.3.443"]
[org.clojure/tools.logging "0.4.0"]
[org.clojure/tools.reader "1.1.0"]
[org.clojure/clojurescript "1.9.946"]
[org.clojure/math.numeric-tower "0.0.4"]
;; apps.nrepl-cider
[cider/cider-nrepl "0.15.1"]
;; seems weasel is optional, I can integrate cider with piggieback to support browser support. It's bad to introduce weasel api into my cljs file
[com.cemerick/piggieback "0.2.2"]
;; cms
[ring "1.6.3"]
[ring/ring-defaults "0.3.1"]
[ring-webjars "0.2.0" :exclusions [com.fasterxml.jackson.core/jackson-core]]
[compojure "1.6.0"]
[hiccup "1.0.5"]
;; my licence expire on 2017/05/17, upgrade not supported, so only 0.9.5561 supported. can register new account?
;; this is free but not for open source
;;[com.datomic/datomic-pro "0.9.5561" :exclusions [commons-codec org.apache.httpcomponents/httpclient org.slf4j/slf4j-nop]]
[com.datomic/datomic-free "0.9.5561.62" :exclusions [commons-codec org.apache.httpcomponents/httpclient org.slf4j/slf4j-nop com.google.guava/guava]]
[org.webjars.bower/tether "1.4.0"]
[org.webjars/bootstrap "4.0.0-beta.2"]
[org.webjars.bower/semantic "2.2.13"]
[endophile "0.2.1"]
[buddy/buddy-auth "2.1.0"]
[oauth-clj "0.1.15" :exclusions [commons-logging]]
[org.danielsz/system "0.4.0"]
[com.cemerick/pomegranate "1.0.0" :exclusions [commons-logging]]
[prone "1.1.4"]
[ring-logger "0.7.7"]
;; logging
[org.slf4j/jcl-over-slf4j "1.7.25"]
[ch.qos.logback/logback-classic "1.2.3"]
;; for tools
[enlive "1.1.6"]
[com.draines/postal "2.0.2"]
;; for incanter-example
[net.mikera/core.matrix "0.61.0"]
[incanter "1.9.0"]
;; for ml week 4
[net.mikera/imagez "0.12.0"]
[quil "2.6.0"]
;; mvn install:install-file -DgroupId=apps -DartifactId=extruder -Dversion=1.02 -Dpackaging=jar -Dfile=extruder.jar -DgeneratePom=true -DcreateChecksum=true
[apps/extruder "1.02"]
[apps/peasycam "202"]
[apps/shapes3d "2.2"]
;; func-plot
[prismatic/dommy "1.1.0"]
[hipo "0.5.2"]
[cljsjs/three "0.0.87-0"]
;; sources
[org.processing/core "3.3.6" :classifier "sources"]
]
;;:jvm-opts ["-Xmx6g" "-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"]
;; cider don't inject this automaticlly, so duplicate with code in nrepl-cider
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
:plugins [[lein-ancient "0.6.14"]]
)
REPL
启动脚本:
(ns apps.cljs-rt-browser
(:require [clojure.tools.logging :as log]
[clojure.java.io :as io]
[hiccup.core :refer [html]]
[hiccup.page :refer [include-js]]
[hiccup.element :refer [javascript-tag]]
cljs.build.api
cljs.repl.browser
cemerick.piggieback
))
(def repl-client-url "http://192.168.124.5:9000/repl")
(def index-hcp
[:html
[:head]
[:body
(include-js "goog/base.js" "main.js")
(javascript-tag (cljs.build.api/compile {} '(require 'clojure.browser.repl)))
(javascript-tag (cljs.build.api/compile {} (apply list `(clojure.browser.repl/connect ~repl-client-url))))]])
(def index-path "out/index.html")
(defn -main []
;; generate:
;; module system: goog/base.js, module info of google: goog/deps.js, module of google: goog/**
;; module info of other: main.js, module of others
(cljs.build.api/build "src" {:output-to "out/main.js"
:browser-repl true
:verbose true
})
;; repl will serve static, so just generate index.html
(when-not (. (io/file index-path) exists)
(spit index-path (html index-hcp)))
;; exclude "." from static-dir to avoid overwrite of repl compiled files: out/out/**
(cemerick.piggieback/cljs-repl (cljs.repl.browser/repl-env :static-dir ["out/"]) :repl-verbose true))
(-main)