cursive-ide / cursive

Cursive: The IDE for beautiful Clojure code
590 stars 7 forks source link

Cursive REPL with FigWheel #970

Closed simax closed 8 years ago

simax commented 9 years ago

I'm having an issue starting a Cursive REPL with FigWheel and my project. The project is ClojureScript front-end with a Clojure back-end.

I've tried the following scenarios:-

Scenario 1

Following the instructions here: https://github.com/bhauman/lein-figwheel/wiki/Running-figwheel-in-a-Cursive-Clojure-REPL

I created a REPL in IntelliJ by doing the following:

  1. Click Run->Edit configurations.
  2. Click the + button at the top left and choose Clojure REPL
  3. Enter a name in the Name field (e.g. "REPL")
  4. Choose the radio button Use clojure.main in normal JVM process
  5. In the Parameters field put script/repl.clj
  6. Click the OK button to save your REPL config.

When I click the 'Run' REPL I see the following output:

Figwheel: Starting server at http://localhost:3449
Focusing on build ids: dev
Compiling "resources/public/js/compiled/app.js" from ["src/cljs"]...
Successfully compiled "resources/public/js/compiled/app.js" in 0.824 seconds.
WARNING: run! already refers to: #'clojure.core/run! in namespace: reagent.ratom, being replaced by: #'reagent.ratom/run!
Started Figwheel autobuilder

Launching ClojureScript REPL for build: dev
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild [id ...])      ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (reload-config)                 ;; reloads build config and resets autobuild
          (build-once [id ...])           ;; builds source one time
          (clean-builds [id ..])          ;; deletes compiled cljs target files
          (fig-status)                    ;; displays current state of system
          (add-dep [org.om/om "0.8.1"]) ;; add a dependency. very experimental
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: Control+C or :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when figwheel connects to your application

If I then browse to http://localhost:3449 I simply get a Page Not Found error and the REPL prompt never appears.

Scenario 2

If I simply run lein figwheel from the terminal without creating and running a Cursive REPL. I see the same output as above but when I browse to http://localhost:3449 my app appears correctly and the REPL prompt appears.

Scenario 3

If I create an empty FigWheel project with lein new figwheel my-app and create a REPL as described in Scenario 1 then browse to http://localhost:3449 my app appears correctly and the REPL prompt appears.

My question is How can I get Scenario 1 to work?

I notice I'm also getting the following warning:

WARNING: run! already refers to: #'clojure.core/run! in namespace: reagent.ratom, being replaced by: #'reagent.ratom/run!

Not sure if this is related or not - its only a warning and it doesn't prevent Scenario 2 and Scenario 3 from working. I've tried to add refer-clojure clauses in the various ns calls, Maybe I've missed one.

This is my Project.clj file

(defproject metime "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.7.0"]
                           [org.clojure/clojurescript "0.0-3297"]
                           [org.clojure/core.async "0.1.346.0-17112a-alpha"]
                           [figwheel "0.3.6"]
                           [figwheel-sidecar "0.3.6"]

                           [cljs-hash "0.0.2"]
                           [com.novemberain/validateur "2.4.2"]
                           [metis "0.3.3"]
                           [ring-cors "0.1.7"]
                           [clj-time "0.9.0"]
                           [digest "1.4.4"]

                           ;; Server
                           [ring "1.4.0-RC2"]
                           [compojure "1.3.4"]
                           [cljs-http "0.1.35"]
                           [yesql "0.5.0-rc3"]
                           [org.xerial/sqlite-jdbc "3.7.2"]
                           [liberator "0.13"]
                           [cheshire "5.5.0"]
                           [prone "0.8.2"]
                           [org.clojure/data.json "0.2.5"]

                           ;; UI
                           [reagent "0.5.0"]
                           [re-frame "0.4.1"]
                           [re-com "0.5.4"]
                           [secretary "1.2.3"]

                           ;; Dev
                           [org.clojure/tools.trace "0.7.8"]
                           [enlive "1.1.5"]
                           [selmer "0.8.0"]
                           [environ "1.0.0"]
                           [expectations "2.1.2"]]

  :plugins [[lein-figwheel "0.3.7"]
            [lein-cljsbuild "1.0.5"]
            [lein-environ "1.0.0"]
            [lein-ring "0.9.6"]
            [lein-asset-minifier "0.2.2"]]

  :source-paths ["src/clj" "src/cljs"]

  :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"]

  ;; Used for data migrations
  :clj-sql-up {:database {:classname "org.sqlite.JDBC"
                          :subprotocol "sqlite"
                          :subname "data/metime.sqlite"}
               :deps [[org.xerial/sqlite-jdbc "3.7.2"]]}

  :ring {:handler metime.core/app :auto-reload? true}

  :min-lein-version "2.5.0"

  :uberjar-name "metime.jar"
  :main metime.server

  :cljsbuild {
              :builds [{:id           "dev"
                        :source-paths ["src/cljs"]

                        :figwheel     {:on-jsload "metime.core/mount-root"}

                        :compiler     {:main                 metime.core
                                       :asset-path           "js/compiled/out"
                                       :output-to            "resources/public/js/compiled/app.js"
                                       :output-dir           "resources/public/js/compiled/out"
                                       :source-map-timestamp true}}
                       {:id           "min"
                        :source-paths ["src/cljs"]
                        :compiler     {:output-to     "resources/public/js/compiled/app.js"
                                       :main          metime.core
                                       :optimizations :advanced
                                       :pretty-print  false}}]}
  :figwheel {
             ;:http-server-root "public"
             ;:nrepl-port       7888
             ;:port             3449
             :css-dirs     ["resources/public/assets/css"]
             :ring-handler metime.core/app
             })
danielcompton commented 9 years ago

I'm pretty sure you shouldn't have [lein-figwheel "0.3.7"] in your plugins. The guide says you need to remove that.

simax commented 9 years ago

Thanks, I've tried all sorts of combinations. Having [lein-figwheel "0.3.7"] in the plugins section allows scenario 2 to work, which is what I'm currently having to do. If I remove it however, I still get Page not found when trying to execute scenario 1. So no luck I'm afraid.

rarous commented 8 years ago

I think this can be closed, linked instructions works well.

danielcompton commented 8 years ago

Closing for now, reopen if this is still an issue.