I wasn't able to add #inst values to var metadata. Compilation failed to Not supported: class java.time.Instant
error
Steps to reproduce:
$ mkdir src
$ echo '(ns core) (def ^{:time #inst "2023-10-07"} foo :foo)' > src/core.cljs
$ clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.11.60"}}}' -M --main cljs.main --compile core
Expected: Compilation is successful
Actual:
Unexpected error compiling at (REPL:1).
Not supported: class java.time.Instant
Full report at:
/var/folders/0p/vtdv4p053pd6gkx8d5p98h000000gn/T/clojure-15941611179751768055.edn
Analysis:
CLJS-3291 changed the #inst reader to produce java.time.Instant
instead of java.util.Date
. The analysis cache transit writer is failing to write java.time.Instant
because it only knows how to serialize java.util.Date
.
Workaround:
(def foo :foo)
(alter-meta #'foo assoc :time #inst "2023-10-07")
Full report:
{:clojure.main/message
"Unexpected error compiling at (REPL:1).\nNot supported: class java.time.Instant\n",
:clojure.main/triage
{:file
#object[java.io.File 0x608f79a8 "/Users/mikko/Documents/Projects/sharetribe/instant-cljs2/src/core.cljs"],
:clojure.error/phase :compilation,
:clojure.error/class java.lang.Exception,
:clojure.error/cause "Not supported: class java.time.Instant"},
:clojure.main/trace
{:via
[{:type clojure.lang.ExceptionInfo,
:message
"failed compiling file:/Users/mikko/Documents/Projects/sharetribe/instant-cljs2/src/core.cljs",
:data
{:file
#object[java.io.File 0x608f79a8 "/Users/mikko/Documents/Projects/sharetribe/instant-cljs2/src/core.cljs"],
:clojure.error/phase :compilation},
:at
[cljs.compiler$compile_file$fn__4809 invoke "compiler.cljc" 1768]}
{:type java.lang.RuntimeException,
:message
"java.lang.Exception: Not supported: class java.time.Instant",
:at
[com.cognitect.transit.impl.WriterFactory$1
write
"WriterFactory.java"
65]}
{:type java.lang.Exception,
:message "Not supported: class java.time.Instant",
:at
[com.cognitect.transit.impl.AbstractEmitter
marshal
"AbstractEmitter.java"
195]}],
:trace
[[com.cognitect.transit.impl.AbstractEmitter
marshal
"AbstractEmitter.java"
195]
[com.cognitect.transit.impl.JsonEmitter
emitMap
"JsonEmitter.java"
171]
[com.cognitect.transit.impl.AbstractEmitter
emitMap
"AbstractEmitter.java"
86]
[com.cognitect.transit.impl.AbstractEmitter
marshal
"AbstractEmitter.java"
185]
[com.cognitect.transit.impl.JsonEmitter
emitMap
"JsonEmitter.java"
171]
[com.cognitect.transit.impl.AbstractEmitter
emitMap
"AbstractEmitter.java"
86]
[com.cognitect.transit.impl.AbstractEmitter
marshal
"AbstractEmitter.java"
185]
[com.cognitect.transit.impl.JsonEmitter
emitMap
"JsonEmitter.java"
171]
[com.cognitect.transit.impl.AbstractEmitter
emitMap
"AbstractEmitter.java"
86]
[com.cognitect.transit.impl.AbstractEmitter
marshal
"AbstractEmitter.java"
185]
[com.cognitect.transit.impl.JsonEmitter
emitMap
"JsonEmitter.java"
171]
[com.cognitect.transit.impl.AbstractEmitter
emitMap
"AbstractEmitter.java"
86]
[com.cognitect.transit.impl.AbstractEmitter
marshal
"AbstractEmitter.java"
185]
[com.cognitect.transit.impl.AbstractEmitter
marshalTop
"AbstractEmitter.java"
212]
[com.cognitect.transit.impl.JsonEmitter emit "JsonEmitter.java" 41]
[com.cognitect.transit.impl.WriterFactory$1
write
"WriterFactory.java"
62]
[cljs.vendor.cognitect.transit$write invokeStatic "transit.clj" 171]
[cljs.vendor.cognitect.transit$write invoke "transit.clj" 168]
[cljs.analyzer$write_analysis_cache$fn__3960
invoke
"analyzer.cljc"
4771]
[cljs.analyzer$write_analysis_cache
invokeStatic
"analyzer.cljc"
4770]
[cljs.analyzer$write_analysis_cache invoke "analyzer.cljc" 4757]
[cljs.compiler$emit_source invokeStatic "compiler.cljc" 1642]
[cljs.compiler$emit_source invoke "compiler.cljc" 1557]
[cljs.compiler$compile_file_STAR_$fn__4778
invoke
"compiler.cljc"
1671]
[cljs.compiler$with_core_cljs invokeStatic "compiler.cljc" 1477]
[cljs.compiler$with_core_cljs invoke "compiler.cljc" 1466]
[cljs.compiler$compile_file_STAR_ invokeStatic "compiler.cljc" 1655]
[cljs.compiler$compile_file_STAR_ invoke "compiler.cljc" 1648]
[cljs.compiler$compile_file$fn__4809 invoke "compiler.cljc" 1753]
[cljs.compiler$compile_file invokeStatic "compiler.cljc" 1728]
[cljs.compiler$compile_file invoke "compiler.cljc" 1704]
[cljs.closure$compile_file invokeStatic "closure.clj" 657]
[cljs.closure$compile_file invoke "closure.clj" 635]
[cljs.closure$fn__6472 invokeStatic "closure.clj" 731]
[cljs.closure$fn__6472 invoke "closure.clj" 725]
[cljs.closure$fn__6381$G__6374__6388 invoke "closure.clj" 553]
[cljs.closure$compile_sources$iter__6598__6602$fn__6603
invoke
"closure.clj"
1102]
[clojure.lang.LazySeq sval "LazySeq.java" 42]
[clojure.lang.LazySeq seq "LazySeq.java" 51]
[clojure.lang.Cons next "Cons.java" 39]
[clojure.lang.RT next "RT.java" 713]
[clojure.core$next__5451 invokeStatic "core.clj" 64]
[clojure.core$dorun invokeStatic "core.clj" 3143]
[clojure.core$doall invokeStatic "core.clj" 3149]
[clojure.core$doall invoke "core.clj" 3149]
[cljs.closure$compile_sources invokeStatic "closure.clj" 1098]
[cljs.closure$compile_sources invoke "closure.clj" 1087]
[cljs.closure$build invokeStatic "closure.clj" 3200]
[cljs.closure$build invoke "closure.clj" 3104]
[cljs.build.api$build invokeStatic "api.clj" 231]
[cljs.build.api$build invoke "api.clj" 212]
[cljs.cli$default_compile invokeStatic "cli.clj" 530]
[cljs.cli$default_compile invoke "cli.clj" 486]
[cljs.cli$compile_opt invokeStatic "cli.clj" 542]
[cljs.cli$compile_opt invoke "cli.clj" 540]
[cljs.cli$main invokeStatic "cli.clj" 703]
[cljs.cli$main doInvoke "cli.clj" 692]
[clojure.lang.RestFn applyTo "RestFn.java" 139]
[clojure.core$apply invokeStatic "core.clj" 669]
[clojure.core$apply invoke "core.clj" 662]
[cljs.main$_main invokeStatic "main.clj" 65]
[cljs.main$_main doInvoke "main.clj" 56]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.core$apply invokeStatic "core.clj" 667]
[clojure.main$main_opt invokeStatic "main.clj" 514]
[clojure.main$main_opt invoke "main.clj" 510]
[clojure.main$main invokeStatic "main.clj" 664]
[clojure.main$main doInvoke "main.clj" 616]
[clojure.lang.RestFn applyTo "RestFn.java" 137]
[clojure.lang.Var applyTo "Var.java" 705]
[clojure.main main "main.java" 40]],
:cause "Not supported: class java.time.Instant",
:phase :compilation}}