7
votes

I need to share a namespace between my Clojure (Garden) and my ClojureScript (Reagent).

Currently the project folder looks like this:

src/
  clj/
    name/
      css.clj
  cljs/
    name/
      core.cljs
  cljc/
    name/
      config.cljc

The config.cljc file has the following namespace: (ns name.config).

I've tried to reference this namespace from inside clj/name/css.clj with a require.

(ns name.css
  (:require [name.config :as config]))

However, this results in a compile error from Garden.

Caused by: java.io.FileNotFoundException: Could not locate name/config__init.class or name/config.clj on classpath.

I guess it's not even checking for cljc files.

I added "src/cljc" to the :source-paths vector in project.clj and :garden :builds but I get the same error even after restarting the build processes.

I see this behaviour on Clojure 1.7.0 and 1.8.0.

It might also be worth mentioning that it works without issues in ClojureScript (with Figwheel handling the build). I can require and use the new namespace without problems.

It seems like I must be missing something really simple, because none of the documentation around .cljc files even mentions requiring them.

2

2 Answers

5
votes

Check if you’re using Clojure 1.7 or above in your project.clj. This error message:

Caused by: java.io.FileNotFoundException: Could not locate name/config__init.class or name/config.clj on classpath.

indicates that you’re using Clojure 1.6 or below, as those versions of Clojure only know to look for .class or .clj files.

0
votes

I got this same error when I moved a file from .clj to .cljc in my project. I did lein clean but that had no effect. Eventually I renamed the module namespace and that fixed it.

(My guess is that there was some sort of cache of compiled modules and it was referencing a module which no longer existed, but the cljc wasn't re-compiled because a module of that name was still cached.)

When I renamed the module namespace it worked, with no other changes to the code.