I'm trying to use cljsjs/moment with an existing chestnut template app, but I get the following from figwheel
No such namespace: cljsjs.moment, could not locate cljsjs/moment.cljs, cljsjs/moment.cljc, or Closure namespace "cljsjs.moment"
Please see src/cljs/some_awesome_app/system.cljs
My dependencies:
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/clojurescript "1.9.854" :scope "provided"]
[com.cognitect/transit-clj "0.8.300"]
[ring "1.6.2"]
[ring/ring-defaults "0.3.1"]
[bk/ring-gzip "0.2.1"]
[radicalzephyr/ring.middleware.logger "0.6.0"]
[compojure "1.6.0"]
[environ "1.1.0"]
[com.stuartsierra/component "0.3.2"]
[org.danielsz/system "0.4.0"]
[org.clojure/tools.namespace "0.2.11"]
[org.omcljs/om "1.0.0-alpha48"]
[clj-http "3.7.0"]
[hiccup "2.0.0-alpha1"]
[cheshire "5.8.0"]
[cljsjs/moment "2.17.1-1"]] ;; <--- here it is
My main file:
(ns some-awesome-app.system
(:require [com.stuartsierra.component :as component]
[cljsjs.moment]
[some-awesome-app.components.ui :refer [new-ui-component]]))
I'm getting that error, without even using the library in my code..
Figured it out.
I'm using spacemacs with CIDER. And I was using jack-in instead of jack-in-clojurescript.
All works fine now.
Related
I have a small Clojure project with /project.clj:
(defproject testjackson "0.1.0-SNAPSHOT"
:main testjackson.core
:dependencies [[org.clojure/clojure "1.10.3"]
[ring/ring-json "0.5.0"]])
and /src/testjackson/core.clj:
(ns testjackson.core
(:gen-class)
(:require [ring.middleware.json :refer [wrap-json-body]]))
(defn -main [& _] (println :testing wrap-json-body))
When I run it, it just prints:
$ java -jar target/testjackson-0.1.0-SNAPSHOT-standalone.jar
:testing #object[ring.middleware.json$wrap_json_body 0x37cd92d6 ring.middleware.json$wrap_json_body#37cd92d6]
It runs as expected. I can also execute jdeps on the uberjar to get the list of used modules:
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
java.base,java.desktop,java.sql,jdk.unsupported
However, when I bump ring-json version to 0.5.1, the jdeps call fails:
$ jdeps --print-module-deps --ignore-missing-deps target/testjackson-0.1.0-SNAPSHOT-standalone.jar
Exception in thread "main" java.lang.module.FindException: Module com.fasterxml.jackson.core not found, required by com.fasterxml.jackson.dataformat.smile
at java.base/java.lang.module.Resolver.findFail(Resolver.java:877)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:191)
at java.base/java.lang.module.Resolver.resolve(Resolver.java:140)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:422)
at java.base/java.lang.module.Configuration.resolve(Configuration.java:256)
at jdk.jdeps/com.sun.tools.jdeps.JdepsConfiguration$Builder.build(JdepsConfiguration.java:564)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.buildConfig(JdepsTask.java:603)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:557)
at jdk.jdeps/com.sun.tools.jdeps.JdepsTask.run(JdepsTask.java:533)
at jdk.jdeps/com.sun.tools.jdeps.Main.main(Main.java:49)
How can this be fixed in the context of this small example program?
As near I as can find from searching, jdeps is from way back in Java 9. In fact, the version on my computer won't even accepts the 2 flags you used in the example, and it doesn't even have a --version option. Web searching shows no obvious uses for clojure.
What is the goal here? Your plain code works fine for me:
project.clj deps
:dependencies [
[org.clojure/clojure "1.11.1"]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.1"]
[tupelo "22.05.24b"]
]
:plugins [[com.jakemccrary/lein-test-refresh "0.25.0"]
[lein-ancient "0.7.0"]
]
code
(ns demo.core
(:use tupelo.core)
(:require [ring.middleware.json :refer [wrap-json-body]])
(:gen-class))
(defn -main [& _]
(spyx (type wrap-json-body)))
and results
> lein clean ; lein run
(type wrap-json-body) => ring.middleware.json$wrap_json_body
Speculation
Although my jlink doesn't seem to work right, I can guess a little. Looking at project.clj, we can ask for a tree of depencencies:
> lein deps :tree
[nrepl "0.8.3" :exclusions [[org.clojure/clojure]]]
[org.clojure/clojure "1.11.1"]
[org.clojure/core.specs.alpha "0.2.62"]
[org.clojure/spec.alpha "0.3.218"]
[org.nrepl/incomplete "0.1.0" :exclusions [[org.clojure/clojure]]]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.1"]
[cheshire "5.10.0"]
[com.fasterxml.jackson.core/jackson-core "2.10.2"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.10.2"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.10.2"]
[tigris "0.1.2"]
[ring/ring-core "1.9.2"]
[commons-fileupload "1.4"]
[commons-io "2.6"]
[crypto-equality "1.0.0"]
[crypto-random "1.2.0"]
[ring/ring-codec "1.1.3"]
[commons-codec "1.15"]
So we see that ring-json needs cheshire, which needs jackson.
Going back to ring-json 0.5.0 we see different version of cheshire and jackson:
> lein deps :tree
[nrepl "0.8.3" :exclusions [[org.clojure/clojure]]]
[org.clojure/clojure "1.11.1"]
[org.clojure/core.specs.alpha "0.2.62"]
[org.clojure/spec.alpha "0.3.218"]
[org.nrepl/incomplete "0.1.0" :exclusions [[org.clojure/clojure]]]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.0"]
[cheshire "5.9.0"]
[com.fasterxml.jackson.core/jackson-core "2.9.9"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.9.9"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.9.9"]
[tigris "0.1.1"]
[ring/ring-core "1.7.1"]
[clj-time "0.14.3"]
[joda-time "2.9.9"]
[commons-fileupload "1.3.3"]
[commons-io "2.6"]
[crypto-equality "1.0.0"]
[crypto-random "1.2.0"]
[ring/ring-codec "1.1.1"]
[commons-codec "1.11"]
Note that you can force newer versions in project.clj if you want. Just manually require cheshire and jackson, and put them near the top!
:dependencies [
; priority 1 libs
[org.clojure/clojure "1.11.1"]
[cheshire "5.10.2"]
[com.fasterxml.jackson.core/jackson-core "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.13.3"]
; priority 2 libs
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.0"]
; [tupelo "22.05.24b"]
]
with result
> lcr
time (lein do clean, run)
:type ring.middleware.json$wrap_json_body
8.11s user 0.59s system 218% cpu 3.989 total
~/expr/demo >
~/expr/demo >
~/expr/demo > lein deps :tree
[cheshire "5.10.2"]
[tigris "0.1.2"]
[com.fasterxml.jackson.core/jackson-core "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-cbor "2.13.3"]
[com.fasterxml.jackson.core/jackson-databind "2.13.3"]
[com.fasterxml.jackson.core/jackson-annotations "2.13.3"]
[com.fasterxml.jackson.dataformat/jackson-dataformat-smile "2.13.3"]
[nrepl "0.8.3" :exclusions [[org.clojure/clojure]]]
[org.clojure/clojure "1.11.1"]
[org.clojure/core.specs.alpha "0.2.62"]
[org.clojure/spec.alpha "0.3.218"]
[org.nrepl/incomplete "0.1.0" :exclusions [[org.clojure/clojure]]]
[prismatic/schema "1.2.1"]
[ring/ring-json "0.5.0"]
[ring/ring-core "1.7.1"]
[clj-time "0.14.3"]
[joda-time "2.9.9"]
[commons-fileupload "1.3.3"]
[commons-io "2.6"]
[crypto-equality "1.0.0"]
[crypto-random "1.2.0"]
[ring/ring-codec "1.1.1"]
[commons-codec "1.11"]
Perhaps something similar will solve your problem. It has been crucial for me in the past.
Specifically, the jackson libs absolutely must
have all 3 sub-libraries on the same version. Because dependent libs
often don't update their own deps like jackson as often as they could, it is easy to get version conflicts when 2 or more libs each require different versions of jackson. The above technique of forcing a specific version of jackson (or any other lib) is a lifesaver. IMHO, it is also much better than trying to put in a bunch of lein :exclusions clauses.
I would like to use cloverage so I can check how much of my code base is tested by speclj. However after installing cloverage as a lein plugin and running: lein cloverage I see the following exception:
Exception in thread "main" java.io.FileNotFoundException:
Could not locate app/unit/core_spec__init.class or app/unit/core_spec.clj on classpath.
Please check that namespaces with dashes use underscores in the Clojure file name.,
compiling:(/private/var/folders/w_/yt926bqs21g44f257yz05ctsjbv948/T/form-init4597524674545750330.clj:1:125)
Caused by: java.io.FileNotFoundException: Could not locate app/component/core_spec__init.class or app/component/core_spec.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
I've not used cloverage before so what to check if I'm using it correctly, has anyone come across this issue before?
This is what my project.clj looks like:
(defproject app version
:dependencies [
[org.clojure/clojure "1.8.0"]
[org.clojure/tools.logging "0.4.0"]
[org.clojure/tools.cli "0.3.5"]
[org.clojure/data.json "0.2.6"]
[org.postgresql/postgresql "9.4-1201-jdbc41"]
[org.slf4j/slf4j-log4j12 "1.7.25"]
[log4j/log4j "1.2.17" :exclusions [javax.mail/mail
javax.jms/jms
com.sun.jmdk/jmxtools
com.sun.jmx/jmxri]]
[metosin/compojure-api "1.1.11"]
[metosin/ring-swagger "0.24.3"]
[compojure "1.6.0"]
[cheshire "5.8.0"]
[ring "1.6.3"]
[ring/ring-json "0.4.0"]
[ring-logger "0.7.7"]
[environ "1.1.0"]
[korma "0.4.3"]
[blackwater "0.0.9"]
[prismatic/schema "1.1.7"]
[siili/humanize "0.1.1"]
[amazonica "0.3.117"]
]
:main app.cli.core
:plugins [
[lein-ring "0.12.1"]
[lein-cloverage "1.0.10"]
[speclj "3.3.2"]
]
:test-paths ["spec"]
:profiles {
:uberjar {:aot :all}
:user {
:plugins
[[cider/cider-nrepl "0.16.0"]
[lein-kibit "0.1.6"]
[nightlight/lein-nightlight "1.0.0"]
[lein-cloverage "1.0.6"]
[jonase/eastwood "0.2.3"]
[lein-cloverage "1.0.9"]
[speclj "3.3.2"]]
}
:dev {
:dependencies [
[ring-mock "0.1.3"]
[clj-http "3.7.0"]
[org.clojure/data.json "0.2.6"]
[speclj "3.3.2"]
[clj-time "0.14.2"]
[listora/again "0.1.0"]
[environ "1.1.0"]
]
}
}
)
spec/app/component/core_spec.clj
(ns app.component.core_spec
(:require [speclj.core :refer :all]
[clojure.data.json :as json]
[clj-http.client :as client]
[clj-time.core :as t]
[again.core :as again]
[clj-time.format :as f]
[environ.core :refer [env]]))
(describe "app"
; tests and things...
)
Your problem is probably unrelated to Cloverage specifically. It looks like you're trying to require app.unit.core-spec, and that file either doesn't exist or hasn't been properly named (don't forget source files should have underscores, not dashes!)
In my project.cli I have a dependency on clj-http that is used for tests only, with clj-http.client.
When I look at the uberjar file created for that project, I see that the class fils associated with this dependency are included. That makes the jar file bigger than it need be.
So, is there a way to define a dependency in clojure such that it is only used during tests, and is not included in the uberjar?
I know that I could do this in a pom.xml, but the pom.xml is generated when using clojure, so I only have recourse to something that works in the project.clj file.
To add more colour, my project.clj looks like this
(defproject aproject "0.1.0-SNAPSHOT"
:description "A project"
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/data.json "0.2.6"]
[compojure "1.5.0"]
[hiccup "1.0.5"]
[http-kit "2.1.18"]
[org.clojure/tools.logging "0.3.1"]
[ch.qos.logback/logback-classic "1.1.7"]
[ring/ring-devel "1.4.0"]]
:plugins [[lein-ring "0.9.7"]]
:ring {:handler aproject.core/app-routes}
:main ^:skip-aot aproject.core
:target-path "target/%s"
:resources-paths ["resources/"]
:profiles {:uberjar {:aot :all}
:dev {:dependencies [[peridot "0.4.3"]
[midje "1.8.3"]]
:plugins [[lein-midje "3.2.1"]]
:aliases {"test" ["midje"]}}
:test {:dependencies [[clj-http "3.5.0"]
[midje "1.8.3"]]
:plugins [[lein-midje "3.2.1"]]}
})
I am running the tests like this:
lein with-profile test midje :filters dt
What I am seeing is:
Exception in thread "main" java.io.FileNotFoundException: Could not locate midje/util/ecosystem__init.class or midje/util/ecosystem.clj on classpath., compiling:(/private/var/folders/7l/0fwd_7ls1m19q3_z1_tgg1w80000gn/T/form-init7253661442775183594.clj:1:125)
at clojure.lang.Compiler.load(Compiler.java:7391)
The filter probably does not affect this, but just in case the test looks like this:
(ns aproject.deployment.core
(:require [midje.sweet :refer :all]
[clj-http.client :as client]
[peridot.core :as p]
[clojure.data.json :as json]
[front-end.core :as fe]))
(facts "'aproject' deployed" :dt
(let [response (client/get "http://localhost:8080/ping")]
(response :status) => 200
))
I can see that the test profile is being triggered, and I seem to have the dependency for midje, and the plugin, but ...?
Thanks
Nathan
Add it to the :test profile, then run your tests with lein with-profile test midje :filters dt. Generate your uberjar as usual, lein uberjar and it shouldn't include the extra files.
I'm using Clojure 1.7.0 and ClojureScript 1.7.170. For formatting dates I'm using cljs-time 0.3.14.
The following example in figwheel crash in my machine while it works in another:
=> (require 'cljs-time.core 'cljs-time.format)
=> (cljs-time.format/unparse (cljs-time.format/formatter "yyyy") (cljs-time.core/date-time 2010 10 3))
#object[TypeError TypeError: Cannot read property 'call' of null]
clojure.string.replace_with.G__31150__delegate (jar:file:/Users/juanjo/.m2/repository/org/clojure/clojurescript/1.7.170/clojurescript-1.7.170.jar!/clojure/string.cljs:37:10)
clojure.string.replace_with.G__31150 (jar:file:/Users/juanjo/.m2/repository/org/clojure/clojurescript/1.7.170/clojurescript-1.7.170.jar!/clojure/string.cljs:33:10)
clojure.string/replace-all (jar:file:/Users/juanjo/.m2/repository/org/clojure/clojurescript/1.7.170/clojurescript-1.7.170.jar!/clojure/string.cljs:29:13)
Function.clojure$string$replace (jar:file:/Users/juanjo/.m2/repository/org/clojure/clojurescript/1.7.170/clojurescript-1.7.170.jar!/clojure/string.cljs:53:8)
Function.cljs.core.apply.cljs$core$IFn$_invoke$arity$2 (jar:file:/Users/juanjo/.m2/repository/org/clojure/clojurescript/1.7.170/clojurescript-1.7.170.jar!/cljs/core.cljs:3448:18)
cljs.core/apply (jar:file:/Users/juanjo/.m2/repository/org/clojure/clojurescript/1.7.170/clojurescript-1.7.170.jar!/cljs/core.cljs:3439:1)
cljs_time$format$unparse (jar:file:/Users/juanjo/.m2/repository/com/andrewmcveigh/cljs-time/0.3.14/cljs-time-0.3.14.jar!/cljs_time/format.cljs:439:4)
In the working computer, this is the result:
=> (cljs-time.format/unparse (cljs-time.format/formatter "yyyy") (cljs-time.core/date-time 2010 10 3))
"2010"
This is the error I'm getting in chrome:
Update
This are my dependencies:
:dependencies [[org.clojure/clojure "1.7.0"]
[selmer "0.9.5"]
[markdown-clj "0.9.82"]
[environ "1.0.1"]
[ring-middleware-format "0.7.0"]
[metosin/ring-http-response "0.6.5"]
[bouncer "0.3.3"]
[org.clojure/tools.nrepl "0.2.12"]
[org.webjars/bootstrap "3.3.6"]
[org.webjars/jquery "2.1.4"]
[com.taoensso/timbre "4.1.5-SNAPSHOT"]
[com.taoensso/tower "3.0.2"]
[compojure "1.4.0"]
[ring-webjars "0.1.1"]
[ring/ring-defaults "0.1.5"]
[ring "1.4.0" :exclusions [ring/ring-jetty-adapter]]
[mount "0.1.6"]
[migratus "0.8.8"]
[conman "0.2.7"]
[org.postgresql/postgresql "9.4-1203-jdbc41"]
[org.clojure/clojurescript "1.7.170"]
[reagent "0.5.1"]
[reagent-forms "0.5.13"]
[reagent-utils "0.1.5"]
[com.domkm/silk "0.1.1"]
[kibu/pushy "0.3.6"]
[org.clojure/core.async "0.2.374"]
[cljs-ajax "0.5.2"]
[metosin/compojure-api "0.23.1"]
[metosin/ring-swagger-ui "2.1.3"]
[org.immutant/web "2.1.1"]
[com.carouselapps/free-form "0.2.0"]
[re-frame "0.6.0"]
[com.andrewmcveigh/cljs-time "0.3.14"]]
Exception: Exception in thread "main" java.io.FileNotFoundException: Could not locate hiccup/form_helpers__init.class or hiccup/form_helpers.clj on classpath:
I'm trying to get a toy compojure app up and running. The original app was from CloudBees and their ClickStart app for Clojure/Compojure. I'm trying to add a simple form (that won't persist anything yet) using hiccup form_helpers but I'm getting a ClassNotFound exception. Here's what I've done:
project.clj:
(defproject mywebapp "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:dependencies [[org.clojure/clojure "1.4.0"]
[compojure "1.1.1"]
[hiccup "1.0.1"]]
:plugins [[lein-ring "0.7.3"]]
:ring {:handler mywebapp.routes/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.3"]]}})
views.clj:
(ns mywebapp.views
(:use [hiccup core page]
[hiccup form-helpers :only [form-to label text-area submit-button]]))
...
(defn shout-form []
[:div {:id "shout-form" }
(form-to [:post "/form"]
(label "shout" "What do you want to SHOUT?")
[:br]
(text-area "shout")
[:br]
(submit-button "SHOUT!"))])
...
Ah, looks like I just had an old example of forms in hiccup. form_helpers was from a previous version.
if I change my views.clj file from this:
(:use [hiccup form-helpers])
to look like this:
(:use [hiccup form])
(and presumably this would work though i haven't tested it):
(:use [hiccup form :only [form-to label text-area submit-button]])
I don't get the error anymore.
To clarify: the package used to be called "form_helpers" and is now simply called "form".