nrepl / piggieback

nREPL support for ClojureScript REPLs
480 stars 48 forks source link

Can't change/establish root binding of: *cljs-repl-options* with set #48

Closed EduardoMRB closed 9 years ago

EduardoMRB commented 9 years ago

I'm trying to get piggieback to work on my project and I just can't.

I think that it has something to do with nrepl-middleware in project.clj so I'll post it here to see if I'm doing something stupid.

(defproject tasks "0.0.1-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"]
                 [org.clojure/clojurescript "0.0-2913"]
                 [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                 [io.pedestal/pedestal.service "0.3.1"]

                 ;; Remove this line and uncomment one of the next lines to
                 ;; use Tomcat or Immutant instead of Jetty:
                 [io.pedestal/pedestal.jetty "0.3.1"]
                 ;; [io.pedestal/pedestal.tomcat "0.3.1"]
                 ;; [io.pedestal/pedestal.immutant "0.3.1"]

                 [com.datomic/datomic-pro "0.9.5078" :exclusions [org.slf4j/slf4j-nop
                                                                  joda-time]]

                 [ch.qos.logback/logback-classic "1.1.2" :exclusions [org.slf4j/slf4j-api]]
                 [org.slf4j/jul-to-slf4j "1.7.7"]
                 [org.slf4j/jcl-over-slf4j "1.7.7"]
                 [org.slf4j/log4j-over-slf4j "1.7.7"]

                 [ns-tracker "0.2.2"]

                 [org.omcljs/om "0.8.6"]
                 [com.cemerick/piggieback "0.1.5"]]
  :min-lein-version "2.0.0"
  :resource-paths ["config", "resources"]
  :datomic {:schemas ["resources/datomic/schema.edn"]}
  :repositories {"my.datomic.com" {:url "https://my.datomic.com"
                                   :creds :gpg}}
  :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}
  :profiles {:dev {:aliases {"run-dev" ["trampoline" "run" "-m" "tasks.server/run-dev"]}
                   :dependencies [[io.pedestal/pedestal.service-tools "0.3.1"]
                                  [midje "1.6.3"]
                                  [figwheel "0.2.3-SNAPSHOT"]]}}
  :plugins [[lein-cljsbuild "1.0.5"]
            [lein-figwheel "0.2.3-SNAPSHOT"]]
  :cljsbuild {:builds [{:id "dev"
                        :source-paths ["src-cljs"]
                        :compiler {:optimizations :none
                                   :output-to "resources/public/js/tasks.js"
                                   :output-dir "resources/public/js/out"
                                   :source-map true
                                   :pretty-print true}}]}
  :main ^{:skip-aot true} tasks.server)

Error output

Compiling client js ...
Waiting for browser to connect ...

java.lang.IllegalStateException: Can't change/establish root binding of: *cljs-repl-options* with set
tasks.server=> 
alexandergunnarson commented 9 years ago

I'm having the same problem. I made it work with Clojure 1.6.0 instead of 1.7.0-alpha5, but I don't remember what other changes I made.

alexandergunnarson commented 9 years ago

This is also an issue with Weasel, here: https://github.com/tomjakubowski/weasel/issues/40

Here's my configuration in case it helps:

(defproject ramsey "1.0.0-SNAPSHOT"
  :description "Clojure web app"
  :jvm-opts []
  :url "http://exampleapp.herokuapp.com"
  :license {:name "Eclipse Public License v1.0"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :main  ramsey.web
  :dependencies
    [; CLOJURE
     [org.clojure/clojure       "1.7.0-alpha5"]
     [compojure                 "1.1.8"       ]
     [ring/ring-jetty-adapter   "1.2.2"       ]
     [environ                   "0.5.0"       ]
     ; CLOJURESCRIPT
     [org.clojure/clojurescript "0.0-2913"    ]
     [org.omcljs/om             "0.8.8"       ]
     [racehub/om-bootstrap      "0.3.1"       ]
     [sablono                   "0.2.20"      ]
     [weasel                    "0.6.0"       ]]
  :min-lein-version "2.0.0"
  :plugins
    [[environ/environ.lein "0.2.1"]
     [lein-cljsbuild       "1.0.5"]]
  :cljsbuild {
    :builds [{:id "ramsey"
              :source-paths ["src/cljs"]
              :compiler {
                :output-to "ramsey.js"
                :output-dir "out"
                :optimizations :none ; CHANGE THIS
                :source-map true}}]}
  :hooks [environ.leiningen.hooks]
  :uberjar-name "ramsey-standalone.jar"
  :profiles
    {:dev
      {:dependencies [[com.cemerick/piggieback "0.1.5"]]
       :plugins 
         [[com.cemerick/austin     "0.1.6"]
          [com.cemerick/piggieback "0.1.5"]]
       :repl-options
         {:nrepl-middleware
           [cemerick.piggieback/wrap-cljs-repl]}}
     :production {:env {:production true}}})
jmckitrick commented 9 years ago

I'm having this same issue again as well. I'll add my project.clj just for fun:

(defproject pts "1.0.0-SNAPSHOT" :description "Public Talk Scheduler" :url "http://pts-dev.herokuapp.com" :min-lein-version "2.5.0" :dependencies [[org.clojure/clojure "1.6.0"] [org.clojure/clojurescript "0.0-3058"] [org.clojure/core.async "0.1.346.0-17112a-alpha"] [http-kit "2.1.19"] [ring "1.3.2"] [reagent "0.5.0-alpha"] [cljs-ajax "0.3.10"] [compojure "1.3.2"] [ring-middleware-format "0.4.0"] [cheshire "5.4.0"] [clj-pdf "2.0.0"] [jayq "2.5.4"] [com.draines/postal "1.11.3"] [org.postgresql/postgresql "9.3-1101-jdbc4"] [yesql "0.4.0"] [clj-time "0.9.0"] [com.cemerick/friend "0.2.1"] [clj-jwt "0.0.12"] [clojurewerkz/scrypt "1.2.0"] [org.clojure/data.codec "0.1.0"] [org.clojure/data.csv "0.1.2"] [org.clojure/core.cache "0.6.4"] ;;[figwheel "0.2.5-SNAPSHOT"] [environ "1.0.0"]] :plugins [[lein-ring "0.9.2"] [lein-cljsbuild "1.0.5"] [com.cemerick/clojurescript.test "0.3.3"] [cider/cider-nrepl "0.9.0-SNAPSHOT"] ;;[lein-figwheel "0.2.5-SNAPSHOT"] [lein-environ "1.0.0"]] :profiles {:dev {:dependencies [[ring-mock "0.1.5"] [org.clojars.runa/conjure "2.1.3"] [com.cemerick/clojurescript.test "0.3.1"] [com.cemerick/piggieback "0.1.5"] [weasel "0.6.0"]] :cljsbuild {:test-commands {"unit-test" ["phantomjs" :runner "resources/es5-shim.js" "resources/public/js/unit-test.js"]} :builds {:test {:source-paths ["src/cljs" "test/cljs"] :compiler {:output-to "resources/public/js/unit-test.js" :optimizations :whitespace :preamble ^:replace ["jquery/jquery-2.1.1.min.js" "reagent/react.js"]}} :main {:source-paths ["src/cljs" "env/dev/cljs"] ; "src/" :compiler {:output-to "resources/public/js/main.js" :output-dir "resources/public/js/out" :optimizations :none ;;:main ;; for use with :optimizations :none ;;:asset-path ;; see above ;;:source-map true ;; only with :optimizations :none, others need path ;;:verbose true ;;:foreign-libs ;; learn this!!! ;;:externs ;; learn this!!! ;;:modules ;; learn this!!! :cache-analysis true :preamble ["jquery/jquery-2.1.1.min.js" ; :optimizations :none "public/vendor/js/bootstrap.min.js" "reagent/react.js"]}}}} :repl-options {:init-ns pts.server :nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]} :source-paths ["env/dev/clj"] :env {:dev? false}}

         :uberjar
         {:main pts.server
          :aot [pts.server]
          :uberjar-name "pts.jar"
          :hooks [leiningen.cljsbuild]
          :cljsbuild {:builds
                      {:prod
                       {:source-paths ["src/cljs"]
                        :compiler {:output-to "resources/public/js/main.js"
                                   :optimizations :advanced
                                   :cache-analysis true
                                   :static-fns true
                                   :elide-asserts true
                                   :pretty-print false
                                   :preamble ["jquery/jquery-2.1.1.min.js"
                                              "public/vendor/js/bootstrap.min.js"
                                              "reagent/react.js"]}}}}}}

;;:hooks [leiningen.cljsbuild] :main pts.server :aliases {"testall" ["do" ["clean"] ["test"] ["cljsbuild" "test"]] "omni" ["do" ["clean"] ["deps" "tree"] ["ancient"] ["kibit"] ["bikeshed"]]} ;;:global-vars {warn-on-reflection true} :source-paths ["src/clj" "src/sql" "src/cljs" "target/classes"] :test-paths ["test/clj" "test/cljs"] :repl-options {:timeout 180000})

cemerick commented 9 years ago

Unrelated, ClojureScript 0.0-2913 seems to be borked; I consistently get Namespace "goog.string" already declared when starting the compiler, which then tosses an exception.

I took both @alexandergunnarson's and @EduardoMRB's project files, and was able to use each of them as-is (with the exception of updating the ClojureScript dep to 3058):

$ lein repl
...
tasks.server=> (require 'cljs.repl.node)
nil
tasks.server=> (cemerick.piggieback/cljs-repl :repl-env (cljs.repl.node/repl-env))
ClojureScript Node.js REPL server listening on 51829
Type `:cljs/quit` to stop the ClojureScript REPL
nil
cljs.user=> (reduce + #js [1 2 4])
7
cljs.user=> js/process.env.LANG
"en_US.UTF-8"

I tried to replicate the issue with different versions of clojure, java, and leiningen, but with no success (failure!).

I see elsewhere that people are having trouble using piggieback with trampoline; that's not going to work (see #34).

I'm unfortunately at a loss as to what might be causing this issue for some people. Clearly some environmental issue, but nothing obvious comes to mind now that project.clj configuration has been ruled out.

swannodette commented 9 years ago

I see no one has bothered to actually drop a stack trace on this one :)

jmckitrick commented 9 years ago

I can do that.... one sec.....

Jonathon McKitrick

On Wed, Mar 11, 2015 at 11:14 AM, David Nolen notifications@github.com wrote:

I see no one has bothered to actually drop a stack trace on this one :)

Reply to this email directly or view it on GitHub https://github.com/cemerick/piggieback/issues/48#issuecomment-78282963.

jmckitrick commented 9 years ago

Exception in thread "main" java.lang.IllegalStateException: Can't change/establish root binding of: cljs-repl-options with set, compiling:(/private/var/folders/kf/_v_8_1n13017_4ls3x8f8rsw9sbd91/T/form-init2939948288601084359.clj:1:124) at clojure.lang.Compiler.load(Compiler.java:7142) at clojure.lang.Compiler.loadFile(Compiler.java:7086) at clojure.main$load_script.invoke(main.clj:274) at clojure.main$init_opt.invoke(main.clj:279) at clojure.main$initialize.invoke(main.clj:307) at clojure.main$null_opt.invoke(main.clj:342) at clojure.main$main.doInvoke(main.clj:420) at clojure.lang.RestFn.invoke(RestFn.java:421) at clojure.lang.Var.invoke(Var.java:383) at clojure.lang.AFn.applyToHelper(AFn.java:156) at clojure.lang.Var.applyTo(Var.java:700) at clojure.main.main(main.java:37) Caused by: java.lang.IllegalStateException: Can't change/establish root binding of: cljs-repl-options with set at clojure.lang.Var.set(Var.java:221) at cemerick.piggieback$cljs_repl.doInvoke(piggieback.clj:177) at clojure.lang.RestFn.invoke(RestFn.java:421) at pts.dev$browser_repl.invoke(dev.clj:9) at clojure.lang.Var.invoke(Var.java:375) at pts.server$ws_repl.invoke(server.clj:498) at pts.server$_main.doInvoke(server.clj:505) at clojure.lang.RestFn.invoke(RestFn.java:397) at clojure.lang.Var.invoke(Var.java:375) at user$eval5.invoke(form-init2939948288601084359.clj:1) at clojure.lang.Compiler.eval(Compiler.java:6703) at clojure.lang.Compiler.eval(Compiler.java:6693) at clojure.lang.Compiler.load(Compiler.java:7130) ... 11 more

Jonathon McKitrick

On Wed, Mar 11, 2015 at 11:15 AM, Jonathon McKitrick jmckitrick@gmail.com wrote:

I can do that.... one sec.....

Jonathon McKitrick

On Wed, Mar 11, 2015 at 11:14 AM, David Nolen notifications@github.com wrote:

I see no one has bothered to actually drop a stack trace on this one :)

Reply to this email directly or view it on GitHub https://github.com/cemerick/piggieback/issues/48#issuecomment-78282963.

swannodette commented 9 years ago

@j-mckitrick yes OK the problem is quite simple. ClojureScript recently in order to not change the function / protocol level API while getting REPL options to all REPL evaluation environments in all cases (even if not taken explicitly as an argument) establishes a root binding for *cljs-repl-options* via binding in the usual way. However piggieback being nREPL middleware doesn't have the usual REPL loop, it must establish the root binding itself (if not already established) where relevant.

jmckitrick commented 9 years ago

Hmm. So that means... there's not a solution yet with the current versions of ClojureScript?

Jonathon McKitrick

On Wed, Mar 11, 2015 at 11:24 AM, David Nolen notifications@github.com wrote:

@j-mckitrick https://github.com/j-mckitrick yes OK the problem is quite simple. ClojureScript recently in order to not change the function / protocol level API while getting REPL options to all REPL evaluation environments in all cases establishes a root binding for cljs-repl-options via binding in the usual way. However piggieback being nREPL middleware doesn't have the usual REPL loop, it must establish the root binding itself (if not already established) where relevant.

Reply to this email directly or view it on GitHub https://github.com/cemerick/piggieback/issues/48#issuecomment-78285198.

swannodette commented 9 years ago

@j-mckitrick it needs to be fixed in piggieback.

cemerick commented 9 years ago

@swannodette I think you're talking about cljs.repl/*repl-opts*? *cljs-repl-options* is a var defined in piggieback, and is the one that piggieback is failing to set! in the stack provided by @j-mckitrick.

Piggieback doesn't touch the cljs.repl/*repl-opts* var at all; that doesn't seem to hinder usage in any way though, as I can bring up and use a ClojureScript REPL using 3058 and piggieback without a problem. Somehow, the piggieback nREPL middleware isn't being put into place properly, despite the project.clj configuration looking right.

cemerick commented 9 years ago

This seems like a longshot, but could someone who is affected by this try requiring nREPL 0.2.7? It looks like Leiningen is currently defaulting to 0.2.6; 0.2.7 fixes the topological sort applied to REPL middleware. To do this, add [org.clojure/tools.nrepl "0.2.7"] to your :dev profile's :dependencies, and try to start a ClojureScript REPL via piggieback: (cemerick.piggieback/cljs-repl)

(FWIW, clojure.tools.nrepl/version will indicate 0.2.7 if the explicit nREPL dependency has properly overridden Leinigen's default.)

swannodette commented 9 years ago

@cemerick oh you're right, apologies for the noise.

alexandergunnarson commented 9 years ago

@cemerick I updated the dependencies with [org.clojure/clojurescript "0.0-3058"] and the dev dependencies with [org.clojure/tools.nrepl "0.2.7"]. Otherwise my project.clj looks the same way. I unfortunately still have the same error as before.

EduardoMRB commented 9 years ago

@cemerick with [org.clojure/clojurescript "0.0-3058"] and [org.clojure/tools.nrepl "0.2.7"] I was able to start a repl with no problems, thank you for your help.

@alexandergunnarson clojure.tools.nrepl/version outputs the correct version of nrepl?

alexandergunnarson commented 9 years ago

@EduardoMRB — never mind, I just realized I was using lein trampoline (I was just calling a SublimeREPL command I had previously customized a while ago). Apparently that doesn't work for some reason, but lein repl works perfectly for me. Sorry for the confusion.

cemerick commented 9 years ago

Excellent; I think we're 2 of 3 reports now working with nREPL 0.2.7 to eliminate the middleware linearization nondeterminism. Any word, @j-mckitrick?

jmckitrick commented 9 years ago

Let me look at this tonight and get back to you.

Jonathon McKitrick

On Mon, Mar 16, 2015 at 4:44 AM, Chas Emerick notifications@github.com wrote:

Excellent; I think we're 2 of 3 reports now working with nREPL 0.2.7 to eliminate the middleware linearization nondeterminism. Any word, @j-mckitrick https://github.com/j-mckitrick?

Reply to this email directly or view it on GitHub https://github.com/cemerick/piggieback/issues/48#issuecomment-81507356.

jmckitrick commented 9 years ago

Sigh. No luck on this, still.

Jonathon McKitrick

On Mon, Mar 16, 2015 at 7:54 AM, Jonathon McKitrick jmckitrick@gmail.com wrote:

Let me look at this tonight and get back to you.

Jonathon McKitrick

On Mon, Mar 16, 2015 at 4:44 AM, Chas Emerick notifications@github.com wrote:

Excellent; I think we're 2 of 3 reports now working with nREPL 0.2.7 to eliminate the middleware linearization nondeterminism. Any word, @j-mckitrick https://github.com/j-mckitrick?

Reply to this email directly or view it on GitHub https://github.com/cemerick/piggieback/issues/48#issuecomment-81507356.

cemerick commented 9 years ago

The work on the new-cljs-repl branch, currently available in 0.2.0-SNAPSHOT, is effectively a rewrite due to the new ClojureScript REPL API, etc. Closing all issues filed against 0.1.x; most (or all) of them should be resolved and/or irrelevant.