Clojure not requiring a cljc file
Asked Answered
P

2

7

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.

Premeditation answered 7/2, 2016 at 15:30 Comment(0)
B
5

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.

Bonnybonnyclabber answered 7/2, 2016 at 18:5 Comment(4)
project.clj has org.clojure/clojure at "1.7.0" and when I boot up a REPL it confirms Clojure 1.7.0. Anything else that needs to be set in project.clj?Premeditation
I get the same problem when I use 1.8.0 too.Premeditation
What version of Leinigen are you using? You might try a more recent one if it exists.Schwerin
@DanPrince can you share your project somewhere?Bonnybonnyclabber
R
0

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.

Rosewood answered 28/9, 2017 at 13:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.