Clojure Light Table无法加载';goog';和其他javascript库

Clojure Light Table无法加载';goog';和其他javascript库,clojure,google-closure-compiler,clojurescript,lighttable,Clojure,Google Closure Compiler,Clojurescript,Lighttable,Light Table 0.7.2使用clojurescript运行“实时”浏览器repl 我只是记录了一个问题的解决方案,这个问题阻碍了我使用Light Table。我找不到任何合适的答案,我花了一段时间才找到解决办法。希望这能帮助其他遇到类似问题的人 当编辑不是项目核心cljs源文件的临时文件(如project.clj:cljsbuild:builds:source path中所指定)时,我在定义命名空间时得到了以下信息: (ns foo) ReferenceError: goog is n

Light Table 0.7.2使用clojurescript运行“实时”浏览器repl

我只是记录了一个问题的解决方案,这个问题阻碍了我使用Light Table。我找不到任何合适的答案,我花了一段时间才找到解决办法。希望这能帮助其他遇到类似问题的人

当编辑不是项目核心cljs源文件的临时文件(如project.clj:cljsbuild:builds:source path中所指定)时,我在定义命名空间时得到了以下信息:

(ns foo)
ReferenceError: goog is not defined
在尝试使用类似dommy的东西时,我会得到:

(ns foo.bar-2
  (:require
    [dommy.core :as dc]
    [domina.xpath :as dx]))
 Error: goog.require could not find: dommy.core
我在这里发现了类似的问题[

这里是$20/光桌讨论/D4xjfDnA2Co/7iaqewIPzGUJ

但是,在第一种情况下,解决方案不起作用。在第二种情况下,我无法理解用户所说的“只是不在LightTable中实时评估clojurescript名称空间并依赖浏览器/DOM行为进行反馈”是什么意思

我之所以不使用项目的主文件,是因为我想在一个单独的repl中做一些快速的一次性操作。这是我在emacs下可以做的事情。通常,在emacs下,我会有主cljs文件,然后是ncider repl。我会将两者放在同一个命名空间中,这样我就可以从任何一个缓冲区更新共享上下文。

假设: 我假设您已经知道如何启动Light Table所需的两个服务器:clojure repl和浏览器

基本上,这个链接:

向我透露了解决办法

似乎任何不在项目src dir下的文件都完全依赖于浏览器“repl”来查找其所需的任何库。因此,解决方案是为要包含在ns中的任何js库向index.html添加标记:

<html>
    <head>
      <script type='text/javascript' id='lt_ws' src='http://localhost:54792/socket.io/lighttable/ws.js'></script>
      <script src="out/goog/base.js" type="text/javascript"></script> <!-- add this -->
    </head>
    <body>
        hello from mies-test
        <script src="out/mies_test.js" type="text/javascript"></script>
    </body>
</html>
2) 运行“lein cljsbuild once”。您需要确保在输出目录下有goog/base.js和cljs/core.js:

@HP_LAPTOP_ENVY /c/vtstuff/clojure_stuff/projects/mies2/out
$ ls *
cljs_deps.js  mies_test.js

cljs:
core.cljs  core.cljs.cache.edn  core.js  core.js.map

clojure:
browser

goog:
array    base.js  disposable  functions  iter  log        mochikit  promise  structs  uri
asserts  debug    dom         html       json  math       net       reflect  testing  useragent
async    deps.js  events      i18n       labs  messaging  object    string   timer

mies2:
core.cljs  core.cljs.cache.edn  core.js  core.js.map
如果你做一个“lein clean”,它将删除“out”目录。做一次“lein cljsbuild”将重建它。如果你想要一个干净的开始,就这样做

3) 刷新浏览器url,例如

file:///C:/vtstuff/clojure_stuff/projects/mies2/index.html
4) 现在,当我跑(ns-foo)时,我得到:

6) 如果要将dommy添加到ns:

(ns foo-2
 (:require [dommy.core :as dommy]))
    #<Error: goog.require could not find: dommy.core>
Error: goog.require could not find: dommy.core
7) 不幸的是,您不能将临时文件与主文件放在同一个ns中

cljs:

(ns  mies2.core)

#<Error: Namespace "mies2.core" already declared.>
Error: Namespace "mies2.core" already declared.
cljs:
(ns mies2.核心)
#
错误:命名空间“mies2.core”已声明。
无论如何,在了解了所有这些之后,我能够运行一个3.js立方体演示。也许当我对实时浏览器“回复”有了更多的了解后,这一切看起来都很明显,但这肯定会在开始时给我带来很多困惑

快乐编码

<head>
   <script type='text/javascript' id='lt_ws' src='http://localhost:61756/socket.io/lighttable/ws.js'></script>
   <script src="out/goog/base.js" type="text/javascript"></script>
   <script src="out/cljs/core.js" type="text/javascript"></script> <!-- add this -->
</head>
(+ 1 1 ) 2

(ns foo) nil

(namespace ::x) "foo"
(ns foo-2
 (:require [dommy.core :as dommy]))
    #<Error: goog.require could not find: dommy.core>
Error: goog.require could not find: dommy.core
(ns foo-3
(:require [mies2.core]))

mies2.core/abc 7
cljs:

(ns  mies2.core)

#<Error: Namespace "mies2.core" already declared.>
Error: Namespace "mies2.core" already declared.