Welcome! Please see the About page for a little more info on how this works.

0 votes
in IO by

With lein dev
i try and use java.io i have this message

The required namespace "clojure.java.io" is not available, it was required by "demo/core/test.cljs".
"clojure/java/io.clj" was found on the classpath. Maybe this library only supports CLJ?

(ns demo.core.test
(:require [clojure.java.io :as jio])

(:body (client/get "http://placehold.it/350x150" {:as :stream}))
(jio.File. "test-file.gif"))


1 Answer

0 votes

A .cljs file is ClojureScript so it's going to be compiled to JavaScript and run either in the browser or on Node.js.

clojure.java.io is part of Clojure and provides a wrapper around Java I/O library functions and therefore can only be used from Clojure (on the JVM) and not ClojureScript.

Perhaps your demo/core/test.cljs file should be Clojure and have a .clj file extension instead?

I did this but i have the same result since i need to call it inside of my view which is a cljs
But what do not get why i do no have this issue with clojure.string only clojure.java.io is not accepted
clojure.string is not Java specific, so it is available for both Clojure and ClojureScript.

clojure.java.io -- and the other namespaces with "java" in their names -- are Clojure-only and you cannot use them from ClojureScript (because ClojureScript compiles to JavaScript, whereas Clojure compiles to JVM bytecode like Java does).
edited by
But then i do exactly the same function in lein repl and everything runs smooth no error
Because lein repl is a Clojure REPL not a ClojureScript REPL.
may be i will try with this cljs library and upload a file

  (:require [reagent.core :refer [render atom]]
            [cljs.core.async :refer [put! chan <! >!]])
  (:require-macros [cljs.core.async.macros :refer [go go-loop]]))