Clojurescript libraries - goog.require could not f

2019-05-02 03:01发布

New to clojurescript, and working through the "Modern CLJS" tutorial here.

It instructs to pull in domina by adding it to the project.clj:

:dependencies [[org.clojure/clojure "1.4.0"]
               [compojure "1.1.5"]
               [domina "1.0.0"]]

And then use it in your script by referencing it in the ns form

(ns cljstut.login
  (:use [domina :only [by-id value]]))

However, when I actually run this in a browser, I see the following in the console log.

goog.require could not find: domina

Seems like I'm missing some declaration somewhere? But as a newb, this whole build process is rather opaque. Any troubleshooting tips are greatly appreciated.

6条回答
家丑人穷心不美
2楼-- · 2019-05-02 03:08

Dependencies in your project.clj file and your namespace declarations look fine.

If you are building your clojurescript code using lein cljsbuild auto, you will need to restart that process. I believe it should automatically pull in new dependencies after a restart.

If that doesn't work, or you aren't using lein cljsbuild auto, try running the lein deps command inside your project's folder manually - it will fetch all missing dependencies from remote repositories.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-05-02 03:09

I got past this error message by putting lines in the right order in the index.html file.

Correct order:

<script src="js/expanding_gases.js" type="text/javascript"></script>
<script type="text/javascript">goog.require("expanding_gases.flow_gases");</script>

Incorrect order:

<script type="text/javascript">goog.require("expanding_gases.flow_gases");</script>
<script src="js/expanding_gases.js" type="text/javascript"></script>

By the way a good read for understanding 'goog' messages is here: https://github.com/clojure/clojurescript/wiki/Quick-Start

查看更多
smile是对你的礼貌
4楼-- · 2019-05-02 03:23

I ran into this same issue while working through the "Modern CLJS" tutorial. My problem was inadvertently adding the "domina" dependency to the :plugins section of project.clj rather than the :dependencies section.

查看更多
Emotional °昔
5楼-- · 2019-05-02 03:26

Also, make sure you have saved your project.clj file and try running lein clean and lein cljsbuild clean.

查看更多
够拽才男人
6楼-- · 2019-05-02 03:31

I'm in the process of updating modern-cljs to the latest versions of the used libs and lein plugins. At the moment I updated the series up to the 7th tutorial of the series. You should now be safe by updating to domina 1.0.2-SNAPSHOT into project.cljs :dependencies and to lein-cljsbuild 0.3.0 into project.cljs :plugins.

Mimmo

查看更多
一夜七次
7楼-- · 2019-05-02 03:31

Just want to add that a typo in the namespace would trigger the same error message:

goog.require could not find: domina

Example (note the missing "j" in modern-cljs):

(ns modern-cls.login
  (:use [domina :only [by-id value]]))

I was using a different project name thus a different namespace just to be brave. It bit me in the ass when I copy-pasted from the guide and the error had me puzzled for a while :)

查看更多
登录 后发表回答