cursive-ide / cursive

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

"Cannot load Clojure form into ClojureScript REPL" (red error) #1285

Open oshyshko opened 8 years ago

oshyshko commented 8 years ago

Summary: can't send forms from editor to an attached ClojureScript REPL.

Here is a screenshot of the problem: https://www.dropbox.com/s/2gessquui612ahj/intellij-cursive.png?dl=0

Prerequisites:

Figwheel: Starting server at http://localhost:3449
Figwheel: Watching build - dev
Compiling "resources/public/js/compiled/hello_world.js" from ["src"]...
Successfully compiled "resources/public/js/compiled/hello_world.js" in 1.171 seconds.
Figwheel: Starting CSS Watcher for paths  ["resources/public/css"]
Figwheel: Starting nREPL server on port: 7888
  1. Open resources/public/index.html in your Browser (e.g. Chrome), naviage to Dev Console. You should see:
  Edits to this text should show up in your developer console.
  Figwheel: trying to open cljs reload socket
  Figwheel: socket connection established
>
  1. Open in IntelliJ / Cursive and import as Leiningen project
  2. Create a REPL configuration:
[+] > Clojure REPL > Remote,
[*] Connect to server
    host: localhost
    port: 7888

Run it. You should see:

Connecting to remote nREPL server...
Clojure 1.7.0
  1. Open script/figwheel.clj and send 2 forms from it to REPL using "Send top form to REPL" hotkey. You should see:
Connecting to remote nREPL server...
Clojure 1.7.0
(use 'figwheel-sidecar.repl-api)
=> nil
(cljs-repl)
Launching ClojureScript REPL for build: dev
Figwheel Controls:
..... <lines skipped> .....
To quit, type: :cljs/quit
=> nil
  1. Open src/hello_world/core.cljs
  2. Make sure you have [cljs] selected (dropdown in REPL)
  3. Put cursor into (ns hello-world.core ...) and press "Send top form to REPL" hotkey. You should see red error saying Cannot load Clojure form into ClojureScript REPL
  4. Repeat previous step with (println "Edits to this ..."). You should see red error saying "Cannot load Clojure form into ClojureScript REPL"
  5. Put cursor into REPL directly, type (js/alert 123) and press Enter. You should see a popup with [OK] button fired by browser.

Expected behavior:

Two last points: the form should be evaluated in browser (observed in Dev Console) and no red error should appear.

realgenekim commented 6 years ago

FWIW, I had this problem exactly as reported.

However, @cursive-ide advised me in Clojurians Slack channel to rename file to .cljc. I did this, wow, and I can now copy forms into CLJS REPL.

I suspect this issue has been resolved since it was filed 2 years ago...

Billal-B commented 2 years ago

There is a drop-down menu in the REPL window, selecting 'cljs' should fix the issue

athanhat commented 2 years ago

Hi Clojurians, this is my setup and the steps to make figwheel and ClojureScript REPL work inside InteliJ IDEA 2021.3.3

lein --version
Leiningen 2.9.1 on Java 11.0.15 OpenJDK 64-Bit Server VM

lein new figwheel figwheel-demo
Generating fresh 'lein new' figwheel project.
Change into your 'figwheel-demo' directory
Then run 'lein figwheel'

cd figwheel-demo
lein figwheel
Figwheel: Cutting some fruit, just a sec ...
Figwheel: Validating the configuration found in project.clj
Figwheel: Configuration Valid ;)
Figwheel: Starting server at http://0.0.0.0:3449
Figwheel: Watching build - dev
Figwheel: Cleaning build - dev
Compiling build :dev to "resources/public/js/compiled/figwheel_demo.js" from ["src"]...
Successfully compiled build :dev to "resources/public/js/compiled/figwheel_demo.js" in 8.181 seconds.
Figwheel: Starting CSS Watcher for paths  ["resources/public/css"]
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
          (print-config id ...)           ;; prints out build configurations
          (fig-status)                    ;; displays current state of system
          (figwheel.client/set-autoload false)    ;; will turn autoloading off
          (figwheel.client/set-repl-pprint false) ;; will turn pretty printing off
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when Figwheel connects to your application
[Rebel readline] Type :repl/help for online help info
ClojureScript 1.10.773
dev:cljs.user!{:conn 3}=>

At this point you know that your figwheel project is compiled, the web server has started at http://0.0.0.0:3449 and the ClojureScript REPL is launched. Now we want to integrate these with InteliJ IDEA and its Cursive plugin.

  1. Open InteliJ IDEA, go to File -> New -> Project from Existing Sources...
  2. Select figwheel-demo directory (OK)
  3. Import project from external model (Leiningen - Next)
  4. Root Directory (Next)
  5. Select Leiningen projects to import (figwheel-demo:0.1.0-SNAPSHOT - Next)
  6. Select project SDK (IDE SDK - Next)
  7. Project name (figwheel-demo - Finish)
  8. Open Project (New Window)
  9. Modify figwheel-demo/dev/user.clj - add (fig-start) expression at the end of the file
  10. Run -> Edit Configurations... -> Add new... (Clojure REPL / Local)
  11. Name (REPL), Run with Leiningen, Common Options - Parameters dev/user.clj
  12. Apply (OK) Run/Debug Configurations to close the pop-up window
  13. Run REPL (Shift + F10)

image

The image shows that we managed to start successfully the Figwheel server and connect it to the local nREPL server Then we tried to evaluate (cljs-repl), i.e. launch Figwheel ClojureScript nREPL middleware library but it failed (see error message)

This the reason for the error message you get "Cannot load ClojureScript form into Clojure REPL" (notice that it is not written correctly on the subject line of the issue). You can reproduce this red error message when you try to send an expression from an open (cljs) file e.g. src/figwheel_demo/core.cljs to the CLJ REPL that is active and running.

This is how you can fix this error

  1. Open and edit project.clj (see my gist for what modifications to include)
  2. launch Figwheel ClojureScript REPL by evaluating (cljs-repl) inside InteliJ nREPL server
  3. Now you can start sending ClojureScript expressions from src/figwheel_demo/core.cljs to Figwheel ClojureScript REPL

image