weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.68k stars 174 forks source link

hiccup 1.0.5 on clojars is broken #100

Closed anthonycagle closed 10 years ago

anthonycagle commented 10 years ago

On new project, gets error: java.lang.IllegalStateException: html-mode already refers to: #'hiccup.util/html-mode in namespace: hiccup.compiler

Building hiccup locally from source and doing 'lein install' eliminates the problem.

weavejester commented 10 years ago

I removed Hiccup from my .m2 directory and tried to reproduce your results in a new project, but it worked fine for me. Was hiccup the only dependency you had in the project?

anthonycagle commented 10 years ago

Yes, I created a new project 'lein new dummy' and then added [hiccup "1.0.5"] to the dependencies in project.clj. 'lein repl' reports the error.

So I just repeated it on my .m2 directory, first deleting and pulling from clojars, then trying to start the repl, then installing hiccup from source. The results are the same. I'm on the US West Coast, so I'm wondering if it's possible we may be hitting different clojar repositories? In any case, the generated jars appear identical except for the ordering of the elements. Just in case it suggest something to you, I've included the expanded jar listings below.

Here's the jar listing from clojars: M Filemode Length Date Time File


-rw-rw-rw- 90 25-Jan-2014 17:49:24 meta-inf/manifest.mf -rw-rw-rw- 2773 25-Jan-2014 17:49:24 META-INF/maven/hiccup/hiccup/pom.xml -rw-rw-rw- 140 25-Jan-2014 17:49:24 META-INF/maven/hiccup/hiccup/pom.properties -rw-rw-rw- 547 25-Jan-2014 17:49:24 META-INF/leiningen/hiccup/hiccup/project.clj -rw-rw-rw- 547 25-Jan-2014 17:49:24 project.clj -rw-rw-rw- 1602 25-Jan-2014 17:49:24 META-INF/leiningen/hiccup/hiccup/README.md -rw-rw-rw- 12917 25-Jan-2014 17:49:24 META-INF/leiningen/hiccup/hiccup/LICENSE.html drwxrwxrwx 0 25-Jan-2014 14:35:16 hiccup/ -rw-rw-rw- 7737 25-Jan-2014 14:34:50 hiccup/compiler.clj -rw-rw-rw- 543 12-Nov-2012 17:42:02 hiccup/core.clj -rw-rw-rw- 1334 6-Oct-2012 12:06:20 hiccup/def.clj -rw-rw-rw- 1023 6-Oct-2012 12:06:20 hiccup/element.clj -rw-rw-rw- 3936 15-Nov-2012 14:28:10 hiccup/form.clj -rw-rw-rw- 407 12-Nov-2012 17:42:02 hiccup/middleware.clj -rw-rw-rw- 2701 21-Jul-2013 19:33:22 hiccup/page.clj -rw-rw-rw- 2566 25-Jan-2014 14:35:16 hiccup/util.clj


             38863                         16 files

Versus from my locally compiled version: M Filemode Length Date Time File


-rw-rw-rw- 94 26-Apr-2014 08:43:54 meta-inf/manifest.mf -rw-rw-rw- 2773 26-Apr-2014 08:43:54 META-INF/maven/hiccup/hiccup/pom.xml -rw-rw-rw- 140 26-Apr-2014 08:43:54 META-INF/maven/hiccup/hiccup/pom.properties -rw-rw-rw- 547 26-Apr-2014 08:43:54 META-INF/leiningen/hiccup/hiccup/project.clj -rw-rw-rw- 547 26-Apr-2014 08:43:54 project.clj -rw-rw-rw- 1602 26-Apr-2014 08:43:54 META-INF/leiningen/hiccup/hiccup/README.md -rw-rw-rw- 12917 26-Apr-2014 08:43:54 META-INF/leiningen/hiccup/hiccup/LICENSE.html drwxrwxrwx 0 26-Apr-2014 08:38:02 hiccup/ -rw-rw-rw- 2566 26-Apr-2014 08:38:02 hiccup/util.clj -rw-rw-rw- 7737 26-Apr-2014 08:38:02 hiccup/compiler.clj -rw-rw-rw- 2701 26-Apr-2014 08:38:02 hiccup/page.clj -rw-rw-rw- 1023 26-Apr-2014 08:38:02 hiccup/element.clj -rw-rw-rw- 407 26-Apr-2014 08:38:02 hiccup/middleware.clj -rw-rw-rw- 1334 26-Apr-2014 08:38:02 hiccup/def.clj -rw-rw-rw- 3936 26-Apr-2014 08:38:02 hiccup/form.clj -rw-rw-rw- 543 26-Apr-2014 08:38:02 hiccup/core.clj


             38867                         16 files

If it didn't work exactly as expected when I install locally from source, I'd suspect misconfiguration in my environment. I saw that a similar error occurred a few months ago and seem to be resolved by just doing 'lein clean'. I also tried that but it had no effect.

weavejester commented 10 years ago

What's the hash of the version in your .m2 directory? e.g.

$ shasum ~/.m2/repository/hiccup/hiccup/1.0.5/hiccup-1.0.5.jar
75940a400111bbb8f80e43325e23100b6e2227bc

Could you also provide the version of Java, Clojure and Leiningen you're using.

Another thought: what's in your profile.clj? This might be being caused by class files in a dependency you're inadvertently bringing in.

anthonycagle commented 10 years ago

Thanks for reminding me that there's an amazing amount of crud in my project.clj! Here's the info you requested.

sha of local version: "19af7c7278328bf98ad1c800dc3b2a1891ed89d7" sha of clojars version: "75940a400111bbb8f80e43325e23100b6e2227bc"

clojure 1.5.1 Leiningen 2.3.4 on Java 1.7.0_55 OpenJDK 64-Bit Server VM java version "1.7.0_55" OpenJDK Runtime Environment (IcedTea 2.4.7) (ArchLinux build 7.u55_2.4.7-1-x86_64) OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

cat ~/.lein/profiles.clj

{:user {:dependencies [[clj-ns-browser "1.3.1"]
                       [difform "1.1.2"]
                       [org.clojars.gjahad/debug-repl "0.3.3"]
                       [spyscope "0.1.4"]
                       [im.chit/vinyasa "0.1.8"]
                       [slamhound "RELEASE"]]
        :plugins [[clj-stacktrace "0.2.7"] 
                  [lein-ancient "0.5.4"]
                  [lein-difftest "2.0.0"]
                  [lein-kibit "0.0.8"] 
                  [lein-marginalia "0.7.1"]
                  [lein-pprint "1.1.1"] 
                  [lein-ring "0.8.10"]
                  [lein-try "0.4.1"]
                  [org.clojure/tools.cli "0.2.4"]]
        :injections [(require 'com.georgejahad.difform) 
                     (require 'alex-and-georges.debug-repl)
                     (require 'spyscope.core)
                     (require 'vinyasa.inject)
                     (vinyasa.inject/inject 'clojure.core '>
                                            '[[clojure.repl doc source]
                                              [clojure.pprint pprint pp]
                                              [alex-and-georges.debug-repl debug-repl]
                                              [com.georgejahad.difform difform]
                                              [clj-ns-browser.sdoc sdoc]])]
        :aliases {"slamhound" ["run" "-m" "slam.hound"]}}}
weavejester commented 10 years ago

The clj-ns-browser dependency is causing you problems. It includes class files from an older version of hiccup, which are conflicting with the source files from Hiccup 1.0.5.

$ jar -tf ~/.m2/repository/clj-ns-browser/clj-ns-browser/1.3.1/clj-ns-browser-1.3.1.jar | grep hiccup
hiccup/compiler$collapse_strs$fn__4986.class
hiccup/compiler$collapse_strs.class
hiccup/compiler$compile_attr_map.class
hiccup/compiler$compile_html.class
...
anthonycagle commented 10 years ago

Aha, thank you!

Still confused about why installing it from source fixed the problem, but that seems to have taken care of the it. Thank you James!

weavejester commented 10 years ago

It might have been that installing from source changed the order of the classpath for the project.

weavejester commented 10 years ago

Opened an issue for this on the clj-ns-browser project.

miguelbermudez commented 10 years ago

Sorry the reopen this issue but I'm having the same problem. Using this discussion, i think I narrowed down the cause to ring-devel's stacktrace.clj. Here's the stacktrace:

(full trace here)

Exception in thread "main" java.lang.ExceptionInInitializerError, compiling:(ring/middleware/stacktrace.clj:1:1)
        at clojure.lang.Compiler.load(Compiler.java:7142)
        at clojure.lang.RT.loadResourceScript(RT.java:370)
        ... 
Caused by: java.lang.ExceptionInInitializerError
        at hiccup.core__init.load(Unknown Source)
        at hiccup.core__init.<clinit>(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:270)
        at clojure.lang.RT.loadClassForName(RT.java:2093)
       ....
        at ring.middleware.stacktrace$eval9902$loading__4958__auto____9903.invoke(stacktrace.clj:1)
        ...
        ... 76 more
Caused by: java.lang.IllegalStateException: *html-mode* already refers to: #'hiccup.util/*html-mode* in namespace: hiccup.compiler
        at clojure.lang.Namespace.warnOrFailOnReplace(Namespace.java:88)
        at clojure.lang.Namespace.intern(Namespace.java:72)
        at clojure.lang.Var.intern(Var.java:158)
        at clojure.lang.RT.var(RT.java:341)
        at hiccup.core$html.<clinit>(core.clj:7)
        ... 101 more
Subprocess failed

Environment:

clojure 1.6.0 Leiningen 2.4.1 on Java 1.7.0_51 Java HotSpot(TM) 64-Bit Server VM java version "1.7.0_51" Java(TM) SE Runtime Environment (build 1.7.0_51-b13) Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

Profile:

(defproject sundial "0.1.0-SNAPSHOT"
            :description "FIXME: write description"
            :url "http://example.com/FIXME"
            :license {:name "Eclipse Public License"
                      :url  "http://www.eclipse.org/legal/epl-v10.html"}
            :dependencies [[org.clojure/clojure "1.6.0"]
                           [compojure "1.1.8"]
                           [environ "0.5.0"]
                           [hiccup "1.0.5"]
                           [liberator "0.12.0"]
                           [org.clojure/data.zip "0.1.1"]
                           [org.clojars.scsibug/feedparser-clj "0.4.0"]
                           [ring/ring-core "1.3.0"]
                           [ring/ring-json "0.3.1"]
                           [ring-server "0.3.1"]]

            :jvm-opts ["-Xmx1G"]

            :aot :all

            :ring {:handler sundial.core/app
                   :init    sundial.core/init
                   :destroy sundial.core/destroy}

            :source-paths ["src/clj"]

            :repl-options {
                            :nrepl-middleware [io.aviso.nrepl/pretty-middleware]}

            :plugins [[lein-gorilla "0.3.2" :exclusions [org.clojure/clojure]]
                      [lein-ring "0.8.11"]]

            :profiles {
                        :dev
                        {:dependencies [[midje "1.6.3"]
                                        [org.clojure/tools.namespace "0.2.5"]
                                        [ring-mock "0.1.5"]
                                        [ring/ring-devel "1.3.0"]]
                         :source-paths ["dev"]
                         :test-paths   ["test/clj"]
                         :ring
                                       {:auto-refresh? true}}

                       :production
                        {:ring
                          {:open-browser? false,
                           :stacktraces?  false,
                           :auto-reload?  false}}})

Since ring-devel uses hiccup maybe this is the same issue? I tried deleting the entries for both hiccup and ring-devel in .m2 folder but still receive the same error as OP.

The hiccup being used in ring-devel is 1.0.5 (https://github.com/ring-clojure/ring/blob/master/ring-devel/project.clj) So I don't think it's a version mismatch.

Apologies, I'm still new to clojure. Please let me if I'm missing something or need to provide more information.

weavejester commented 10 years ago

None of the Ring projects are AOT-compiled, so that's not the source of your problem.

The problem stems from libraries that are AOT-compiled, and include (or possibly reference) compiled class files from an older Hiccup version.

Check your dependencies, particularly those in ~/.lein/profiles.clj, as its easy to forget about dependencies there.

miguelbermudez commented 10 years ago

Thank you for the hint about ~/.lein/profiles.clj. Turns out I also had a dependency on clj-ns-browser. Problem solved.