【发布时间】:2016-03-24 23:41:37
【问题描述】:
我正在尝试使用"foreign" JavaScript dependencies in Clojurescript 来解决问题。我已经阅读了谷歌提供的关于这个主题的大部分内容,但我仍然无法理解这个过程。特别是,我对如何依赖 Clojurescript 中的 jsonld.js 库很感兴趣。
有些点我没有得到:
您是否将
:foreign-libs放入 deps.cljs 或编译器选项(例如,:compiler在 project.clj 中的映射)?:file中的:foreign-libs的值是否被解释为 Java 资源?您将用作外部库的 JavaScript 文件放在哪里?我尝试将它们放入resources和其他地方,但我所有的尝试都导致java.lang.NullPointerException。
重现步骤:
# Create an empty Clojurescript project
lein new figwheel jsonld
# Download jsonld.js library
cd jsonld/resources
curl -O http://cdnjs.cloudflare.com/ajax/libs/jsonld/0.3.15/jsonld.js
# Configure foreign libs in project.clj.
# Add the following into `:compiler` in the dev build:
# :foreign-libs {:file "resources/jsonld.js"
# :provides ["jsonld"]}
lein figwheel # => java.lang.NullPointerException
或者,如果我向deps.cljs 提供以下内容:
{:foreign-libs {:file "jsonld.js"
:provides ["jsonld"]}}
然后 Figwheel 启动,但是当我调用 (require '[jsonld]) 时,我得到了这个错误:
WARNING: JavaScript file found on classpath for library `jsonld`, but does not contain a corresponding `goog.provide` declaration
clojure.lang.ExceptionInfo: No such namespace: jsonld, could not locate jsonld.cljs, jsonld.cljc, or Closure namespace "jsonld" {:tag :cljs/analysis-error}
【问题讨论】:
标签: javascript dependencies clojurescript