java.lang.ClassCastException when starting a new clojurescript project

Hello, I am a newbie to Clojurescript. I am starting a tutorial, but I’ve gotten the following error. Could someone help me resolve the error.

Environment
$ java --version
openjdk 17.0.7 2023-04-18
OpenJDK Runtime Environment (Red_Hat-17.0.7.0.7-4.fc38) (build 17.0.7+7)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.7.0.7-4.fc38) (build 17.0.7+7, mixed mode, sharing)

$ clojure --version
Clojure CLI version 1.11.1.1273

deps.edn
{:deps {:org.clojure/clojurescript {:mvn/version “1.11.60”}}
:paths [“src”]
}

Command
clj -M -m cljs.main --compile my-cljs-project.core --repl

Error Message
Downloading: org/clojure/clojure/1.11.1/clojure-1.11.1.pom from central
Downloading: org/clojure/clojurescript/1.11.60/clojurescript-1.11.60.pom from central
Downloading: org/sonatype/oss/oss-parent/7/oss-parent-7.pom from central
Downloading: org/clojure/core.specs.alpha/0.2.62/core.specs.alpha-0.2.62.pom from central
(…)
Downloading: org/clojure/tools.reader/1.3.6/tools.reader-1.3.6.jar from central
Downloading: com/google/javascript/closure-compiler-unshaded/v20220502/closure-compiler-unshaded-v20220502.jar from central
Downloading: javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar from central
Error building classpath. class clojure.lang.Keyword cannot be cast to class clojure.lang.Symbol (clojure.lang.Keyword and clojure.lang.Symbol are in unnamed module of loader ‘app’)
java.lang.ClassCastException: class clojure.lang.Keyword cannot be cast to class clojure.lang.Symbol (clojure.lang.Keyword and clojure.lang.Symbol are in unnamed module of loader ‘app’)
at clojure.lang.Symbol.compareTo(Symbol.java:107)
at clojure.lang.Util.compare(Util.java:153)
at clojure.lang.APersistentVector.compareTo(APersistentVector.java:442)
at clojure.lang.Util.compare(Util.java:153)
at clojure.core$compare.invokeStatic(core.clj:842)
at clojure.core$compare.invoke(core.clj:833)
at clojure.lang.AFunction.compare(AFunction.java:51)
at java.base/java.util.TimSort.binarySort(TimSort.java:296)
at java.base/java.util.TimSort.sort(TimSort.java:221)
at java.base/java.util.Arrays.sort(Arrays.java:1233)
at clojure.core$sort.invokeStatic(core.clj:3116)
at clojure.core$sort.invokeStatic(core.clj:3103)
at clojure.tools.deps$sort_paths.invokeStatic(deps.clj:564)
at clojure.tools.deps$flatten_libs.invokeStatic(deps.clj:572)
at clojure.tools.deps$make_classpath_map.invokeStatic(deps.clj:591)
at clojure.tools.deps$calc_basis.invokeStatic(deps.clj:750)
at clojure.tools.deps.script.make_classpath2$run_core.invokeStatic(make_classpath2.clj:111)
at clojure.tools.deps.script.make_classpath2$run.invokeStatic(make_classpath2.clj:153)
at clojure.tools.deps.script.make_classpath2$_main.invokeStatic(make_classpath2.clj:203)
at clojure.tools.deps.script.make_classpath2$_main.doInvoke(make_classpath2.clj:174)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Var.applyTo(Var.java:705)
at clojure.core$apply.invokeStatic(core.clj:667)
at clojure.main$main_opt.invokeStatic(main.clj:514)
at clojure.main$main_opt.invoke(main.clj:510)
at clojure.main$main.invokeStatic(main.clj:664)
at clojure.main$main.doInvoke(main.clj:616)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.lang.Var.applyTo(Var.java:705)
at clojure.main.main(main.java:40)

I also tried the following command, and it also fails.

Another try
$ clj -X:deps prep
Downloading: org/clojure/tools.deps.cli/0.9.35/tools.deps.cli-0.9.35.pom from central
Downloading: org/clojure/tools.deps/0.18.1327/tools.deps-0.18.1327.pom from central
Downloading: org/slf4j/slf4j-nop/1.7.36/slf4j-nop-1.7.36.pom from central
(…)
Downloading: org/apache/maven/maven-plugin-api/3.8.6/maven-plugin-api-3.8.6.jar from central
Downloading: org/clojure/core.async/1.6.673/core.async-1.6.673.jar from central
Downloading: org/apache/maven/maven-artifact/3.8.6/maven-artifact-3.8.6.jar from central
Execution error (ClassCastException) at java.util.TimSort/binarySort (TimSort.java:296).
class clojure.lang.Keyword cannot be cast to class clojure.lang.Symbol (clojure.lang.Keyword and clojure.lang.Symbol are in unnamed module of loader ‘app’)

Full report at:
/tmp/clojure-17446059247664034537.edn

Log
$ cat /tmp/clojure-17446059247664034537.edn
{:clojure.main/message
“Execution error (ClassCastException) at java.util.TimSort/binarySort (TimSort.java:296).\nclass clojure.lang.Keyword cannot be cast to class clojure.lang.Symbol (clojure.lang.Keyword and clojure.lang.Symbol are in unnamed module of loader ‘app’)\n”,
:clojure.main/triage
{:clojure.error/class java.lang.ClassCastException,
:clojure.error/line 296,
:clojure.error/cause
“class clojure.lang.Keyword cannot be cast to class clojure.lang.Symbol (clojure.lang.Keyword and clojure.lang.Symbol are in unnamed module of loader ‘app’)”,
:clojure.error/symbol java.util.TimSort/binarySort,
:clojure.error/source “TimSort.java”,
:clojure.error/phase :execution},
:clojure.main/trace
{:via
[{:type java.lang.ClassCastException,
:message
“class clojure.lang.Keyword cannot be cast to class clojure.lang.Symbol (clojure.lang.Keyword and clojure.lang.Symbol are in unnamed module of loader ‘app’)”,
:at [clojure.lang.Symbol compareTo “Symbol.java” 107]}],
:trace
[[clojure.lang.Symbol compareTo “Symbol.java” 107]
[clojure.lang.Util compare “Util.java” 153]
[clojure.lang.APersistentVector
compareTo
“APersistentVector.java”
442]
[clojure.lang.Util compare “Util.java” 153]
[clojure.core$compare invokeStatic “core.clj” 842]
[clojure.core$compare invoke “core.clj” 833]
[clojure.lang.AFunction compare “AFunction.java” 51]
[java.util.TimSort binarySort “TimSort.java” 296]
[java.util.TimSort sort “TimSort.java” 221]
[java.util.Arrays sort “Arrays.java” 1233]
[clojure.core$sort invokeStatic “core.clj” 3116]
[clojure.core$sort invokeStatic “core.clj” 3103]
[clojure.core$sort invoke “core.clj” 3103]
[clojure.tools.deps$sort_paths invokeStatic “deps.clj” 568]
[clojure.tools.deps$sort_paths invoke “deps.clj” 564]
[clojure.tools.deps$flatten_libs invokeStatic “deps.clj” 585]
[clojure.tools.deps$flatten_libs invoke “deps.clj” 570]
[clojure.tools.deps$make_classpath_map invokeStatic “deps.clj” 603]
[clojure.tools.deps$make_classpath_map invoke “deps.clj” 591]
[clojure.tools.deps$calc_basis invokeStatic “deps.clj” 752]
[clojure.tools.deps$calc_basis invoke “deps.clj” 727]
[clojure.tools.deps$create_basis invokeStatic “deps.clj” 843]
[clojure.tools.deps$create_basis invoke “deps.clj” 787]
[clojure.tools.deps.cli.api$prep invokeStatic “api.clj” 61]
[clojure.tools.deps.cli.api$prep invoke “api.clj” 40]
[clojure.lang.Var invoke “Var.java” 384]
[clojure.run.exec$exec invokeStatic “exec.clj” 89]
[clojure.run.exec$exec invoke “exec.clj” 78]
[clojure.run.exec$_main$fn__219 invoke “exec.clj” 216]
[clojure.run.exec$_main invokeStatic “exec.clj” 212]
[clojure.run.exec$_main doInvoke “exec.clj” 180]
[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
“class clojure.lang.Keyword cannot be cast to class clojure.lang.Symbol (clojure.lang.Keyword and clojure.lang.Symbol are in unnamed module of loader ‘app’)”}}

Remove the : from :org – you want a symbol there, not a keyword (org.clojure/clojurescript, not :org.clojure/clojurescript).

@seancorfield Great, thank! It now works!!

After doing some research and reading ‘Learn ClojureScript’, I am also now trying seancorfield/clj-new package. This has created a new ClojureScript project working successfully. Thank you for a great template, seancorfield !

deps.edn

{:aliases
 {:new
  {:extra-deps
   {seancorfield/clj-new {:mvn/version "1.1.309"}}
   :exec-fn clj-new/create
   :exec-args {}}}}

command to create a new project

clj -X:new :template figwheel-main :name learn-cljs/weather :args '["+deps" "--reagent"]'

start a new project
cd weather
clj -M:fig:build

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.