【问题标题】:clojurescript could not locate cljs.core.async.macrosclojurescript 找不到 cljs.core.async.macros
【发布时间】:2013-11-04 14:25:28
【问题描述】:

我在文件 client.cljs 中有以下代码:

(ns onn.client
    (:require [enfocus.core :as ef]
          [enfocus.effects :as effects]
          [enfocus.events :as events]
          [clojure.browser.repl :as repl]
          [goog.net.XhrIo :as xhr]
          [cljs.core.async :as async :refer [chan close!]])
    (:use-macros [enfocus.macros :only [deftemplate defsnippet defaction]])
    (:require-macros [cljs.core.async.macros :refer [go alt!]]
))
;....the actual code follows

项目文件如下所示:

(defproject onn "DEV-SNAPSHOT"
  :description "FIXME: write this!"
  :url "http://exampl.com/FIXME"
  :dependencies [[org.clojure/clojure "1.5.1"]
             [ring/ring-core "1.1.8"]
             [ring/ring-jetty-adapter "1.1.8"]
             [org.clojure/clojurescript "0.0-1820"]
             [org.clojure/core.async "0.1.0-SNAPSHOT"]
             [enfocus "2.0.0-SNAPSHOT"]]
  :plugins [[lein-cljsbuild "0.3.2"]
            [lein-ring "0.8.3"]]
  :cljsbuild {:builds [{:source-paths ["src"],
                    :compiler {:pretty-print true,
                               :output-to "resources/public/js/main.js",
                               :warnings true,
                               :optimizations :whitespace}}]}
  :ring {:handler onn.server/app :port 3000})

...编译时给我这个错误:

Caused by: clojure.lang.ExceptionInfo: 
Could not locate cljs/core/async/macros__init.class or cljs/core/async/macros.clj 
on classpath:  at line 1 src/onn/client.cljs

请注意,我的代码是从这里复制的:https://github.com/Dimagog/AsyncGET/blob/master/cljs/app.cljs 这家伙的项目具有相同的依赖项并且可以正常工作。

知道为什么吗?谢谢!

更新: 我的 cljsbuild 是自动的。重新启动 cljsbuild 后,它编译得很好。谢谢!

【问题讨论】:

  • 修改project.clj后是否重启lein cljsbuild
  • 我没有。我的 cljsbuild 是自动的!重新启动 cljsbuild 后它工作了

标签: clojure clojurescript core.async


【解决方案1】:

当我(错误地)在我对 cljs.core.async 的要求中使用 :include-macros true 时出现此错误:

;; THROWS ERROR
(ns my-ns
  (:require [cljs.core.async :refer [<!] :include-macros true])
  (:require-macros [cljs.core.async.macros :refer [go]]))

删除它有效:

;; DOES NOT THROW ERROR
(ns my-ns
  (:require [cljs.core.async :refer [<!]])
  (:require-macros [cljs.core.async.macros :refer [go]]))

【讨论】:

  • 仅供参考,这是因为宏已移至 cljs.core.async.macros
【解决方案2】:

您的project.clj 文件似乎缺少AsyncGET 项目使用的存储库。

:repositories { "sonatype-oss-public" "https://oss.sonatype.org/content/groups/public/" }

【讨论】:

  • ...或使用正确的 Maven 版本 [org.clojure/core.async "0.1.242.0-44b1e3-alpha"] - 但如果您想要core.async
  • 通常是这样,除了他的代码基于另一个使用 SNAPSHOT 版本的项目。在这种情况下,最好先让代码工作,然后再切换到“适当的 Maven 版本”。
  • 显然正确 - 这就是为什么我没有自己回答的原因,我只是想注意到这一点。一般来说,使用 SNAPSHOT 版本并不是一个很好的做法,因为它们会自动更新,因此会干扰您的版本控制。例如。较早的提交可能无法使用,因为它仅适用于较早的快照。
  • 即使我添加了 :repositories,它的工作原理也是一样的。似乎 cljsbuild 必须重新启动。谢谢
【解决方案3】:

我也遇到过这种情况。运行 lein cljsbuild clean 使 cljsbuild 能够拉入库并成功构建。

【讨论】:

  • 这样的东西可以修复它。正如您所看到的 UPDATE 部分,构建是问题所在。我在后台运行了一个长寿的“lein cljsbuild auto”。一旦我重新启动 cljsbuild 一切正常。
【解决方案4】:

仅当您的错误与 brepl 相关时...

如果您尝试将此代码用于“标准”clojurescript brepl,首先您需要将 clojure 宏代码评估为 repl,然后可以从 brepl 中使用异步宏。此外,您可以尝试在 brepl 上进行交互式编码 @cemerick/austin 工具 https://github.com/cemerick/austin

【讨论】:

    【解决方案5】:

    cljsbuild 是自动的。重启cljsbuild后编译就好了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多