"Cannot load Clojure form into ClojureScript REPL" (red error)
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:
- Leiningen 2.5.3
- Java 1.8.0_51 Java HotSpot(TM) 64-Bit Server VM
- Intellij 14.1.5
- ... with Cursive 1.1.0-14.1
- Google Chrome 48.0.2564.109
Steps to reproduce:
-
$ git clone https://github.com/oshyshko/intellij-cursive-red-error.git -
cd hello-world -
$ lein figwheelYou should see:
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
- Open
resources/public/index.htmlin 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
>
- Open in IntelliJ / Cursive and import as Leiningen project
- 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
- Open
script/figwheel.cljand 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
- Open
src/hello_world/core.cljs - Make sure you have [cljs] selected (dropdown in REPL)
- Put cursor into
(ns hello-world.core ...)and press "Send top form to REPL" hotkey. You should see red error sayingCannot load Clojure form into ClojureScript REPL - Repeat previous step with
(println "Edits to this ..."). You should see red error saying "Cannot load Clojure form into ClojureScript REPL" - 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.
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...
There is a drop-down menu in the REPL window, selecting 'cljs' should fix the issue
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.
- Open InteliJ IDEA, go to File -> New -> Project from Existing Sources...
- Select figwheel-demo directory (OK)
- Import project from external model (Leiningen - Next)
- Root Directory (Next)
- Select Leiningen projects to import (figwheel-demo:0.1.0-SNAPSHOT - Next)
- Select project SDK (IDE SDK - Next)
- Project name (figwheel-demo - Finish)
- Open Project (New Window)
-
Modify figwheel-demo/dev/user.clj - add
(fig-start)expression at the end of the file - Run -> Edit Configurations... -> Add new... (Clojure REPL / Local)
- Name (REPL), Run with Leiningen, Common Options - Parameters
dev/user.clj - Apply (OK) Run/Debug Configurations to close the pop-up window
- Run REPL (Shift + F10)

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
- Open and edit
project.clj(see my gist for what modifications to include) - launch Figwheel ClojureScript REPL by evaluating (cljs-repl) inside InteliJ nREPL server
- Now you can start sending ClojureScript expressions from
src/figwheel_demo/core.cljsto Figwheel ClojureScript REPL
