使用om-tools.dom编译clojurescript时出错

时间:2017-06-08 11:03:00

标签: clojurescript om

尝试这个Om&反应教程https://www.codementor.io/reactjs/tutorial/build-single-page-app-with-react-om-clojurescript。编译clojurescript时,我收到错误clojure.lang.ExceptionInfo: Don't know how to create ISeq from: clojure.lang.Symbol at line 1 {:tag :cljs/analysis-error, :file nil, :line 1, :column 1}

显然原因在于om-tools.dom。有人可以解释我做错了吗?

core.cljs:

(ns spa-tutorial.core

  (:require [om.core :as om :include-macros true]
            [om-tools.dom :as dom :include-macros true]
            [om-tools.core :refer-macros [defcomponent]]
            [secretary.core :as sec :include-macros true]
            [goog.events :as events]
            [goog.history.EventType :as EventType]))

(enable-console-print!)

(def app-state (atom {:text "Hello world!"}))

(om/root
  (fn [app owner]
    (reify om/IRender
      (render [_]
        (dom/h1 nil (:text app)))))
  app-state
  {:target (. js/document (getElementById "app"))})

project.clj:

(defproject spa-tutorial "0.1.0-SNAPSHOT"
  :description "FIXME: write this!"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.clojure/clojurescript "0.0-2755"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [org.omcljs/om "0.8.8"]
                 [prismatic/om-tools "0.4.0"]
                 [http-kit "2.1.19"]
                 [secretary "1.2.3"]]
  :plugins [[lein-cljsbuild "1.0.5"]]
  :source-paths ["src" "target/classes"]
  :clean-targets ["out/spa_tutorial" "out/spa_tutorial.js"]
  :cljsbuild {
    :builds [{:id "spa-tutorial"
              :source-paths ["src"]
              :compiler {
                :main spa-tutorial.core
                :output-to "out/spa_tutorial.js"
                :output-dir "out"
                :optimizations :none
                :verbose true}}]})

堆栈跟踪:

clojure.lang.ExceptionInfo: failed compiling file:out/om_tools/dom.cljs {:file #<File out/om_tools/dom.cljs>}
at clojure.core$ex_info.invoke(core.clj:4403)
at cljs.compiler$compile_file.invoke(compiler.clj:1050)
at cljs.closure$compile_file.invoke(closure.clj:343)
at cljs.closure$eval3178$fn__3179.invoke(closure.clj:394)
at cljs.closure$eval3114$fn__3115$G__3105__3122.invoke(closure.clj:301)
at cljs.closure$compile_from_jar.invoke(closure.clj:386)
at cljs.closure$eval3173$fn__3174.invoke(closure.clj:400)
at cljs.closure$eval3114$fn__3115$G__3105__3122.invoke(closure.clj:301)
at cljs.closure$get_compiled_cljs.invoke(closure.clj:463)
at cljs.closure$cljs_dependencies.invoke(closure.clj:507)
at cljs.closure$add_dependencies.doInvoke(closure.clj:529)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invoke(core.clj:626)
at cljs.closure$build.invoke(closure.clj:1081)
at cljs.closure$build.invoke(closure.clj:1020)
at cljsbuild.compiler$compile_cljs$fn__3416.invoke(compiler.clj:81)
at cljsbuild.compiler$compile_cljs.invoke(compiler.clj:80)
at cljsbuild.compiler$run_compiler.invoke(compiler.clj:180)
at user$eval3548$iter__3584__3588$fn__3589$fn__3607.invoke(form-init1935966926108010861.clj:1)
at user$eval3548$iter__3584__3588$fn__3589.invoke(form-init1935966926108010861.clj:1)
at clojure.lang.LazySeq.sval(LazySeq.java:40)
at clojure.lang.LazySeq.seq(LazySeq.java:49)
at clojure.lang.RT.seq(RT.java:484)
at clojure.core$seq.invoke(core.clj:133)
at clojure.core$dorun.invoke(core.clj:2855)
at clojure.core$doall.invoke(core.clj:2871)
at user$eval3548.invoke(form-init1935966926108010861.clj:1)
at clojure.lang.Compiler.eval(Compiler.java:6703)
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: clojure.lang.ExceptionInfo: Don't know how to create ISeq 
from: clojure.lang.Symbol at line 1  {:tag :cljs/analysis-error, :file 
nil, :line 1, :column 1}
at clojure.core$ex_info.invoke(core.clj:4403)
at cljs.analyzer$error.invoke(analyzer.clj:299)
at cljs.analyzer$analyze_seq.invoke(analyzer.clj:1634)
at cljs.analyzer$analyze$fn__1802.invoke(analyzer.clj:1723)
at cljs.analyzer$analyze.invoke(analyzer.clj:1716)
at cljs.analyzer$parse_ns$fn__1819$fn__1824.invoke(analyzer.clj:1801)
at cljs.analyzer$parse_ns$fn__1819.invoke(analyzer.clj:1801)
at cljs.analyzer$parse_ns.invoke(analyzer.clj:1789)
at cljs.compiler$compile_file.invoke(compiler.clj:1032)
... 39 more
Caused by: java.lang.IllegalArgumentException: Don't know how to create 
ISeq from: clojure.lang.Symbol

1 个答案:

答案 0 :(得分:0)

Clojure错误消息(没有clojure.spec)是获得的品味。消息Don't know how to create ISeq from: clojure.lang.Symbol表示ClojureScript期望一个序列(ISeq接口),但它获得symbol

这是因为:refer-macros true的语法对编译器无效。您正在使用较新版本的Clojure来编译旧教程。

现在ClojureScript需要一系列导入的宏(例如:refer-macros [first-macro second-macro]),而不是布尔符号(例如:refer-macros true)。虽然后者syntax was valid在旧版本的ClojureScript中。

当您将依赖项更新为较新版本并删除代码编译的:refer-macro时。即,

project.clj

(defproject spa-tutorial "0.1.0-SNAPSHOT"
  :description "FIXME: write this!"
  :url "http://example.com/FIXME"
  :dependencies [[org.clojure/clojure "1.8.0"]
                 [org.clojure/clojurescript "1.9.473"]
                 [org.clojure/core.async "0.3.443"]
                 [org.omcljs/om "1.0.0-beta1"]
                 [prismatic/om-tools "0.4.0"]]
  :plugins [[lein-cljsbuild "1.1.6"]]
  :source-paths ["src" "target/classes"]
  :clean-targets ["out/spa_tutorial" "out/spa_tutorial.js"]
  :cljsbuild {:builds [{:id "spa-tutorial"
                        :source-paths ["src"]
                        :compiler {:main spa-tutorial.core
                                   :output-to "out/spa_tutorial.js"
                                   :output-dir "out"
                                   :optimizations :none
                                   :verbose true}}]})

core.cljs

(ns spa-tutorial.core
  (:require [om.core :as om]
            [om-tools.dom :as dom]
            [om-tools.core :refer-macros [defcomponent]]
            [goog.events :as events]
            [goog.history.EventType :as EventType]))

(enable-console-print!)

(def app-state (atom {:text "Hello world!"}))

(om/root
 (fn [app owner]
   (reify om/IRender
     (render [_]
       (dom/h1 nil (:text app)))))
 app-state
 {:target (. js/document (getElementById "app"))})

我建议切换到一个新的教程,该教程也使用Figwheel(一个很棒的库,可以在浏览器中重新加载热代码)。例如Basic Tutorial of the Om wiki