6

lein cljsbuild is having trouble finding a namespace/file that's defined right alongside another namespace/file unless I make sure they're compiled in a certain order.

My directory layout looks like this:

project/
  project.clj
  src/
    cljs/
      contempo/
        common/
          defs.cljs
        view/
          core.cljs
          navigation.cljs

navigation.cljs has some stuff to build Om components for navigating around the page, and core.cljs is the main entry point for this particular page. navigation.cljs starts with:

(ns contempo.view.navigation (:require ...))

core.cljs starts with:

(ns contempo.view.core (:require [contempo.view.navigation :as navigation]))

When I run lein cljsbuild, I get:

solace:Groov jfischer$ lein cljsbuild auto
Compiling ClojureScript.
Compiling "war/view/js/app.js" from ["src/cljs/contempo/common" "src/cljs/contempo/view"]...
Compiling "war/view/js/app.js" failed.
clojure.lang.ExceptionInfo: failed compiling file:src/cljs/contempo/view/core.cljs

... snipped stacktrace ...

Caused by: clojure.lang.ExceptionInfo: No such namespace: contempo.view.navigation at line 1 src/cljs/contempo/view/core.cljs

I can get it to work by removing all references to contempo.view.navigation from core.cljs, running lein cljsbuild auto and letting the compile finish, then putting them back and saving (so cljsbuild picks up the changes), but that's silly and shouldn't be necessary.

My project.clj looks like:

(defproject contempo "0.0.0-SNAPSHOT"
  :description "Experimenting with ClojureScript and Om"
  :dependencies [[org.clojure/clojure "1.6.0"]
                 [org.clojure/clojurescript "0.0-2740"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [org.omcljs/om "0.8.7"]]

  :plugins [[lein-cljsbuild "1.0.4"]]

  :clean-targets ^{:protect false} ["war/view/js/app.js"
                                    "war/view/js/out"]

  :cljsbuild {:builds [{:id "view-dev"
                        :source-paths ["src/cljs/contempo/common"
                                       "src/cljs/contempo/view"]
                        :compiler {:output-to "war/view/js/app.js"
                                   :output-dir "war/view/js/out"
                                   :optimizations :none
                                   :cache-analysis true
                                   :source-map true}}]})

Is there anything obvious I'm doing wrong? This looks pretty similar to every ClojureScript project I've looked at.

Update: Tiny skeleton project that shows the error is up here: namespace-error-demo.zip

3
  • Works for me without errors/warnings. I suspect that either you have circular dependencies or one of the source files fail to compile. Also, it might be worth trying using single source path "src/cljs/contempo/" Commented Feb 6, 2015 at 12:26
  • Checked for circular dependencies, collapsed it down to just one source-path, and actually removed almost all the code, and I still get the error. A tiny project that demonstrates it is available here: namespace-error-demo.zip Commented Feb 7, 2015 at 0:40
  • 1
    I just downloaded and compiled the demo without problems. Try with lein clean. If that doesn't work go to your ~/.m2/ directory and delete your Clojurescript and Clojure dependencies, they might be in a bad state. Commented Feb 7, 2015 at 13:23

2 Answers 2

6

The issue ended up being: I wasn't obeying the rules for how namespaces are resolved.

With source paths of src/cljs/contempo/common and src/cljs/contempo/view, if I required the contempo.view.whatever namespace, the compiler would look for it at src/cljs/contempo/common/contempo/view/whatever.cljs and src/cljs/contempo/view/contempo/view/whatever.cljs.

I had to use src/cljs as the source directory. What I wanted to pull off (leaving out code for a given page that didn't need it) was kind of silly (since it'd be pulling in all of ClojureScript anyway) and is now properly addressed thanks to proper Google Closure Module support in ClojureScript.

Sign up to request clarification or add additional context in comments.

Comments

4

I was having this same problem all of today. In my case, the root cause was having .cljs files with "-" in the name. I only discovered this was the problem after switching to 0.0-3030, which provides better error messages for the strict file path to namespace conventions that more recent versions of the cljs compiler have.

You might want to try changing :source-paths to ["src/cljs"]

1 Comment

Thanks so much! I was having the exact same problem and couldn't figure it out without your comment!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.