【问题标题】:lein cljsbuild fails with untraceable error. How do you troubleshoot cljsbuild errors?lein cljsbuild 失败并出现无法追踪的错误。如何解决 cljsbuild 错误?
【发布时间】:2019-02-12 23:23:57
【问题描述】:

我没有看到任何编译日志文件,终端中的错误不足以让我进一步排除故障。 如何获得更详细的错误日志记录或如何解决此问题?

下面堆栈跟踪的前几行

Compiling ClojureScript...
Compiling ["resources/public/js/app.js"] from ["src/cljs"]...
Compiling ["resources/public/js/app.js"] failed.
clojure.lang.ExceptionInfo: failed compiling file:resources\public\js\out\cljs\core.cljs {:file #object[java.io.File 0x7c5d1d25 "resources\\public\\js\\out\\cljs\\core.cljs"], :clojure.error/phase :compilation}
        at cljs.compiler$compile_file$fn__3901.invoke(compiler.cljc:1706)
        at cljs.compiler$compile_file.invokeStatic(compiler.cljc:1666)

我有一个简单的 cljs 文件,内容如下

(ns moose.core)   
(defn run []
  (.write js/document "This is not the end!"))

我的 project.clj 对 cljsbuild 有以下配置

:cljsbuild
  {:builds [{:id           "dev"
             :source-paths ["src/cljs"]
             :figwheel {:on-jsload "moose.core/run"
                        :open-urls ["http://localhost:3449/index.html"]}
             :jar true
             :compiler     {:main moose.core 
                            :warnings true
                            :output-dir "resources/public/js/out" 
                            :asset-path "js/out"
                            :output-to "resources/public/js/app.js"}}]}
  :clean-targets ^{:protect false} [:target-path :compile-path "resources/public/js" "dev-target"]

更新 1 按照下面 Alan 的建议,我创建了一个新模板并缩小了原因,以添加一个相当老的库来与 CouchDB 交互

[com.ashafa/clutch "0.4.0"]

问题仍然是如何获取 cljsbuild 的详细/完整日志。

更新 2 原来库在依赖项列表中的位置会产生影响。 如果它出现在[com.cognitect/transit-clj "0.8.313"] 之前编译失败,否则它可以工作。

【问题讨论】:

  • 如果 cljsbuild 为 ClojureScript 1.10.439 及更早版本的失败生成更多信息,将会很有趣。 (ClojureScript 1.10.516 引入了对异常消息的更改。)如果是这样,也许可以编写针对 cljsbuild 的票证以使其针对 1.10.516 进行更新。
  • @MikeFikes 我尝试了 238,439,516 和 520 得到了相同的错误消息,但调用站点不同,而且只是这条附加信息“:clojure.error/phase :compilation”

标签: clojurescript cljsbuild


【解决方案1】:

ClojureScript 中的配置选项没有很好的文档记录。克隆现有(工作)项目并从那里开始是最简单的。我建议从the cljs-template project 开始如下(参见自述文件):

git clone  https://github.com/cloojure/cljs-template.git  demo-0212  ; temp 

> cd demo-0212 
~/expr/demo-0212 > ls -ldF *
-rwxrwxr-x 1 alan alan  222 Feb 12 16:04 npm-install.bash*
-rwxrwxr-x 1 alan alan 4216 Feb 12 16:04 project.clj*
-rw-rw-r-- 1 alan alan 1576 Feb 12 16:04 README.adoc
drwxrwxr-x 3 alan alan 4096 Feb 12 16:04 resources/
drwxrwxr-x 5 alan alan 4096 Feb 12 16:04 src/
drwxrwxr-x 4 alan alan 4096 Feb 12 16:04 test/

~/expr/demo-0212 > ./npm-install.bash 
...<snip>... lots of stuff

此时,您的项目已具备单元测试所需的 npm 内容。

> lein clean
> lein doo phantom test once

;; ======================================================================
;; Testing with Phantom:

doorunner - beginning
doorunner - end

Testing tst.flintstones.dino
test once - enter
globalObject:   #js {:a 1, :b 2, :c 3}
(-> % .-b (+ 5) => 7
(js/makeDino) => #js {:desc blue dino-dog, :says #object[Function]}
dino.desc =>  blue dino-dog
dino.says(5) =>  Ruff-Ruff-Ruff-Ruff-Ruff!
:keep-words ("am" "having" "today")
:re-seq ("am" "having" "today")
test once - leave

Testing tst.flintstones.wilma
test each - enter
test each - leave
test each - enter
wilmaPhony/stats:    #js {:lipstick red, :height 5.5}
wilma => #js {:desc patient housewife, :says #object[Function]}
test each - leave

Testing tst.flintstones.pebbles
test once - enter
test once - leave

Testing tst.flintstones.slate
logr-slate-enter
logr-slate-leave 3

Testing tst.flintstones.bambam
test each - enter
test each - leave
test each - enter
logr-bambam-enter
logr-bambam-leave 3
test each - leave

Ran 9 tests containing 22 assertions.
0 failures, 0 errors.
lein doo phantom test once  38.73s user 1.05s system 313% cpu 12.701 total

您也可以关闭 figwheel 以在浏览器中查看结果:

> lein clean
> lein figwheel

see new webpage (30-60 sec delay)

------------------------
Figwheel template
Checkout your developer console.

I am a component!

I have bold and red text.
...etc...
------------------------

【讨论】:

  • 非常正确,但是当几乎没有要编译的东西时,不知道为什么编译失败是令人不安的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-11-07
  • 1970-01-01
  • 2021-11-27
  • 1970-01-01
  • 1970-01-01
  • 2020-02-21
  • 2011-11-05
相关资源
最近更新 更多