Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure not requiring a cljc file

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.

like image 971
Dan Prince Avatar asked Feb 07 '16 15:02

Dan Prince


1 Answers

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.

like image 88
Daniel Compton Avatar answered Oct 19 '22 18:10

Daniel Compton