Open imikushin opened 9 years ago
There isn't right now, sorry - I'm planning to update the Cursive page on the ClojureScript wiki soon with how to follow the Quick Start in Cursive.
Here's some brief instructions:
src
directory - your CLJS code will go in there. scripts
directory in the root - your REPL scripts will go here. Mark it as a source root (right click in the project view, Mark directory as...→Sources root, the folder should go blue). scripts
folder and modify the paths in the Quick Start as appropriate.Let me know if you have problems with this, and I'll update this doc and then base the CLJS wiki doc on it.
I've just tried strictly the instructions with Cursive 0.1.62 and Intellij CE 14.1.4, with an additional instruction (that should go in 5. I think) : add scripts/node_repl.clj
in the "Parameters" field of the REPL configuration.
Sadly, not working. Here's the output of the REPL window, I tried to evaluate simple forms with no success :
Starting clojure.main REPL...
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/[*** Too many paths for me ***] clojure.main scripts/node_repl.clj -r
Reading analysis cache for jar:file:/Users/khalid_jebbari/Documents/Clojure/mostly/lib/cljs.jar!/cljs/core.cljs
Compiling src/mostly/core.cljs
Analyzing jar:file:/Users/khalid_jebbari/Documents/Clojure/mostly/lib/cljs.jar!/cljs/nodejs.cljs
Compiling out/cljs/nodejs.cljs
ClojureScript Node.js REPL server listening on 53433
ReferenceError: goog is not defined
at repl:1:1
at net.createServer.socket.on.err (eval at <anonymous> ([stdin]:1:82))
at Domain.bind.b (domain.js:199:18)
at Domain.run (domain.js:139:23)
at Socket.eval (eval at <anonymous> ([stdin]:1:82))
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:392:31)
ReferenceError: goog is not defined
at repl:1:1
at net.createServer.socket.on.err (eval at <anonymous> ([stdin]:1:82))
at Domain.bind.b (domain.js:199:18)
at Domain.run (domain.js:139:23)
at Socket.eval (eval at <anonymous> ([stdin]:1:82))
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:392:31)
Watch compilation log available at: out/watch.log
To quit, type: :cljs/quit
cljs.user=> (+ 1 1)
ReferenceError: cljs is not defined
at repl:11:1
at repl:14:4
at net.createServer.socket.on.err (eval at <anonymous> ([stdin]:1:82))
at Domain.bind.b (domain.js:199:18)
at Domain.run (domain.js:139:23)
at Socket.eval (eval at <anonymous> ([stdin]:1:82))
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:392:31)
cljs.user=> (js/Date.)
ReferenceError: cljs is not defined
at repl:11:1
at repl:14:4
at net.createServer.socket.on.err (eval at <anonymous> ([stdin]:1:82))
at Domain.bind.b (domain.js:199:18)
at Domain.run (domain.js:139:23)
at Socket.eval (eval at <anonymous> ([stdin]:1:82))
at Socket.EventEmitter.emit (events.js:88:17)
at TCP.onread (net.js:392:31)
cljs.user=>
For completeness, here's the code inside src/mostly/core.cljs :
(ns mostly.core
(:require [cljs.nodejs :as node]))
(node/enable-util-print!)
I think it's because of my machine : the node.js version I have is 0.8.0, managed by nvm. Whatever I do with nvm, it always start with node 0.8.0, so I think this version is captured anyway by IntelliJ when it starts. I tried the browser REPL script from Quick Start (really from the mies lein template), and it works fine. Edit : the Quick Start guide says node.js should be version 0.12.x, hence my problem.
I would say your instructions work fine.
I confirm the instructions work fine, with both a node repl and a Browser REPL.
Only remaining thing is running a Nashorn REPL. After setting properly (I think...) the jdk version inside Intellij and my project, I got an error "Nashorn not available under this Java runtime".
Build.clj script :
(require
'[cljs.repl :as repl]
'[cljs.repl.nashorn :as nashorn])
(repl/repl (nashorn/repl-env))
REPL output :
Starting clojure.main REPL...
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/java [*** bla bla ***] clojure.main scripts/nashorn_repl.clj -r
Exception in thread "main" clojure.lang.ExceptionInfo: Nashorn not available under this Java runtime {:type :repl-error}, compiling:(/Users/khalid_jebbari/Documents/Clojure/mostly-adequate-functional-js-in-cljs/scripts/nashorn_repl.clj:5:1)
at clojure.lang.Compiler.load(Compiler.java:7239)
at clojure.lang.Compiler.loadFile(Compiler.java:7165)
at clojure.main$load_script.invoke(main.clj:275)
at clojure.main$script_opt.invoke(main.clj:337)
at clojure.main$main.doInvoke(main.clj:421)
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)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: clojure.lang.ExceptionInfo: Nashorn not available under this Java runtime {:type :repl-error}
at clojure.core$ex_info.invoke(core.clj:4593)
at cljs.repl.nashorn$repl_env.doInvoke(nashorn.clj:191)
at clojure.lang.RestFn.invoke(RestFn.java:397)
at user$eval3.invoke(nashorn_repl.clj:5)
at clojure.lang.Compiler.eval(Compiler.java:6782)
at clojure.lang.Compiler.load(Compiler.java:7227)
... 14 more
Process finished with exit code 1
What's strange is that I looked at the cljs.repl.nashorn
namespace, it starts with :
(util/compile-if (Class/forName "jdk.nashorn.api.scripting.NashornException")
(do ...) ;; then form - setup the Nashorn compiler
(do ...)) ;; else form - simply print the error message I got
When I start a normal Clojure REPL through Leiningen, (Class/forName "jdk.nashorn.api.scripting.NashornException")
returns the Nashorn Class, so I suppose the test should pass.
If you help me, I promise that in exchange I will write the ClojureScript wiki page for Cursive, based on the ClojureScript Quick Start guide and David Nolen's mies leiningen template :)
Bumping the issue, I've stumbled upon a very strange behaviour... In a project (r0man/sablono) I decided to try to evaluate some code in a Nashorn REPL. So I created a simple REPL config (the first option for local REPL, normal JVM process), then typed this :
(require '[cljs.repl :as repl])
;; => nil
(require '[cljs.repl.nashorn :as nashorn])
;; => nil
(repl/repl (nashorn/repl-env))
;; => Here's the problem
I keep getting a small popup with title Input required
and a text input field with a question mark and the label Enter string for standard input
. Seems like the Nashorn REPL tries to get its input from STDIN somehow, and IntelliJ prompts it instead of using the REPL as the input. I'm looking at the repl/repl
options to see if there's a param. In the meantime, it's extremely annoying because each time as click OK or Cancel in the popup it just popups again right after, making my Cursive unusable. I can't focus the IDE itself. Gotta kill it with kill
.
Cursive ~ vim? ;) I just ran into this. You can escape the REPL by typing :cljs/quit
into the prompt.
@DjebbZ I'm running into the same issue with IntelliJ prompting me to enter the form to eval in the repl in the prompt. Otherwise the project is quite different, i.e. no node, the JS is evaluating in chrome browser. Did you find a solution to the issue?
No, I stopped using Nashorn completely, it was just an experiment I'm my case so I didn't spend too much time on it.
@Vinai The issue with the standard input popup is caused by using an nREPL type REPL with something that's expecting a clojure.main style one. If you create your REPL as a clojure.main one, this should work.
@DjebbZ My apologies for missing this earlier!
From Shadow-CLJS wiki, about starting CLJS REPL from within the CLJ one: "This DOES NOT WORK while in nREPL unless your nREPL client supports needs-input." It makes it sound like it could work even with nREPL. Of course, I have no idea how it all works, but maybe it's possible to just change the prompt in the REPL instead of showing a modal dialog with "Enter string for standard input"?
Is there a clear short doc on how to run ClojureScript REPL with Cursive? I couldn't find any. I'm particularly interested in Node.js CLJS REPL.