我正在尝试使用最新的ClojureScript(1.10.741)进行快速入门,但遇到了一些问题。
moon:hello-world lark$ clj --main cljs.main --compile hello-world.core --repl
ClojureScript 1.10.741
cljs.user=>
cljs.user=> (js/alert "Hello CLJS!")
nil
cljs.user=> (require '[hello-world.core :as hello] :reload)
nil
cljs.user=> (hello/average 20 13)
Execution error (TypeError) at (<cljs repl>:1).
Cannot read property 'call' of undefined
cljs.user=> (dir hello)
average
nil
cljs.user=> (source hello)
Source not found
nil
cljs.user=>
首先,有时它不会像上面显示的那样打印“Hello World”。
其次,当我添加了平均函数并尝试重新加载后调用它时,我遇到了执行错误(可重复性错误)。
此外,Node构建也引发了错误
moon:hello-world lark$ clj -m cljs.main --target node --output-to main.js -c hello-world.core
moon:hello-world lark$ node main.js
/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/goog/dom/dom.js:2499
this.document_ = opt_document || goog.global.document || document;
^
ReferenceError: document is not defined
at new goog.dom.DomHelper (/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/goog/dom/dom.js:2499:60)
at Object.goog.dom.getDomHelper (/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/goog/dom/dom.js:87:38)
at new goog.net.xpc.CrossPageChannel (/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/goog/net/xpc/crosspagechannel.js:94:47)
at Function.clojure.browser.net/xpc-connection [as cljs$core$IFn$_invoke$arity$1] (/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/clojure/browser/net.cljs:117:1)
at clojure$browser$net$xpc_connection (/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/clojure/browser/net.cljs:117:1)
at clojure$browser$repl$connect (/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/clojure/browser/repl.cljs:233:9)
at Object.<anonymous> (/Users/lark/code/learn/cljs/clojurescript.org/hello-world/out/clojure/browser/repl/preload.cljs:13:3)
at Module._compile (internal/modules/cjs/loader.js:688:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
at Module.load (internal/modules/cjs/loader.js:598:32)
moon:hello-world lark$
在这种情况下,core.cljs如下所示
(ns hello-world.core)
(println "Hello world!")
上述所有内容在1.10.520版本中都能正常工作。