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"]]
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.
Likely something wrong with my updated build.boot file: https://github.com/laforge49/sente-boot/blob/master/build.boot
(Been on the backend too long!)
I've tried changing the version of clojure and clojurescript. Previously I was not finding class RT, so I've made some progress at least.
Here's my dependencies:
:dependencies '[
[org.clojure/clojure "1.9.0" :scope "provided"]
[org.clojure/core.async "0.4.490"]
[org.clojure/clojurescript "1.9.562"]
[adzerk/boot-reload "0.5.1" :scope "test"]
[adzerk/boot-cljs "2.0.0" :scope "test"]
[com.taoensso/sente "1.14.0-RC2"] ; <--- Sente
[com.taoensso/timbre "4.10.0"]
[http-kit "2.3.0"]
[ring "1.7.1"]
[ring/ring-defaults "0.3.2"] ; Includes `ring-anti-forgery`, etc.
[compojure "1.6.1"] ; Or routing lib of your choice
[hiccup "1.0.5"] ; Optional, just for HTML
[com.cognitect/transit-clj "0.8.313"]
[com.cognitect/transit-cljs "0.8.256"]
[onetom/boot-lein-generate "0.1.3"]]
I get this error:
clojure.lang.ExceptionInfo: clojure/lang/IFn
data: {:file "org\\httpkit\\server.clj", :line 66}
java.lang.NoClassDefFoundError: clojure/lang/IFn
java.lang.ClassNotFoundException: clojure.lang.IFn
...
clojure.core/load/fn core.clj: 6007
clojure.core/load/invokeStatic core.clj: 6006
clojure.core/load core.clj: 5990
...
test_ns.clj
(ns test-ns
(:require [clj-time.jdbc :as tj]
[clj-time.coerce :as tc]))
(.toString (tc/to-sql-date (tc/from-string "2018-09-28")))
=> "2018-09-27"
Why does .toString decrement the date?
The expectation is that the formatted date string would match its input
tc/to-sql-date converts to java.sql.Date class
The .toString method appears to be used by hugsql default jbdc adaptor, which is a project dependency used for sql transactions
project.clj:
(defproject my-project "0.1.0-SNAPSHOT"
...
:min-lein-version "2.0.0"
:dependencies [[org.clojure/clojure "1.10.0-beta1"]
[duct/core "0.7.0-alpha8"]
[duct/module.sql "0.5.0-alpha1"]
[duct/module.logging "0.4.0-alpha1"]
[duct/database.sql.hikaricp "0.3.3"]
[com.walmartlabs/lacinia "0.21.0"]
[com.rpl/specter "1.1.1"]
[net.mikera/core.matrix "0.62.0"]
[com.wsscode/pathom "2.2.4"]
[org.clojure/core.async "0.4.474"]
[org.postgresql/postgresql "42.2.5"]
[org.clojure/core.async "0.4.490"]
[com.layerware/hugsql "0.4.9"]
[cheshire "5.8.1"]
[camel-snake-kebab "0.4.0"]
[hickory "0.7.1"]
[incanter "1.9.3"]
[clj-http "3.9.1"]
[environ "1.1.0"]]
:plugins [[lein-environ "1.1.0"]
[duct/lein-duct "0.11.0-alpha6"]
[lein-exec "0.3.7"]]
:main ^:skip-aot portfolio-management.main
:test-paths ["test"]
:source-paths ["src"]
:target-path "target/%s"
:resource-paths ["resources" "target/resources"]
:prep-tasks ["javac" "compile" ["run" ":duct/compiler"]]
:profiles
{:dev [:project/dev :profiles/dev]
:repl {:prep-tasks ^:replace ["javac" "compile"]
:repl-options {:init-ns user}}
:uberjar {:aot :all}
:profiles/dev {}
:project/dev {:source-paths ["dev/src"]
:resource-paths ["dev/resources"]
:dependencies [[integrant/repl "0.3.1"]
[eftest "0.4.1"]
[kerodon "0.9.0"]
]}})
EDIT
~$ java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
I'm pretty sure that this is a timezone issue as Carcigenicate already pointed out.
from-string parses a string in the UTC timezone and java.sql.Date uses the default JVM timezone.
The returned result is correct if you're in a timezone which is "behind" UTC (to the west) because in those timezones the date 2018-09-28 00:00:00 is actually 2017-09-27.
(java.util.TimeZone/setDefault(java.util.TimeZone/getTimeZone "GMT"))
(.toString (tc/to-sql-date (tc/from-string "2018-09-28")))
;; => "2018-09-28"
(java.util.TimeZone/setDefault(java.util.TimeZone/getTimeZone "GMT-1"))
(.toString (tc/to-sql-date (tc/from-string "2018-09-28")))
;; => "2018-09-27"
You shouldn't use java.sql.Date and expect that it returns a date in the UTC timezone as long as that's not your default timezone.
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!)
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.