Search code examples
clojurescript

CLJS: CompilerException java.lang.RuntimeException: Feature should be a keyword


I get this error whenever I have some code like this in a .cljc file. I couldn't find any answer when I searched for it.

(defn foo
  []
  #?(:cljs
      (f "1")
      (g "2")))

Solution

  • I found out that in #?(:cljs ...) or #?(:clj ...) we can only specify one form.

    Therefore, for multiple functions we can use do for example.

    (defn foo
      []
      #?(:cljs
          (do (f "1")
              (g "2")))
    

    Edit: 9/3/21

    applies not only to functions but more generally to forms

    Eg. (does not work)

    (try
      (something...)
      (catch #(:clj Exception e (error-stuff...)
             #(:cljs :default e (error-stuff...)
    

    should be

    (try
      (something...)
      #(:clj (catch Exception e (clj-error-stuff e)))
      #(:cljs (catch :default e (cljs-errors-stuff e)))