clojurescript

andreiv 2024-10-19T14:32:58.279959Z

Hi! I'm setting up a project with shadow-cljs, I'm having trouble eval-ing from Conjure I'm connecting to the shadow-cljs nREPL server, but when I try to eval the ns form I get:

; (err) Syntax error macroexpanding clojure.core/ns at (chrome_tabs_monitor.cljs:3:1).
; (err) ((:require ["fs" :as fs])) - failed: Extra input spec: :clojure.core.specs.alpha/ns-form
(ns foo.bar
  (:require ["fs" :as fs]))

thheller 2024-10-19T15:17:41.115089Z

the default REPL you connect to is a CLJ REPL, you swtich it to CLJS first. for example via (shadow.cljs.devtools.api/node-repl)

andreiv 2024-10-19T15:20:09.807599Z

got it I think right now i'm launching shadow-cljs cljs-repl script what should i do instead?

andreiv 2024-10-19T15:20:28.649539Z

or you mean i call that from inside the clj repl?

thheller 2024-10-19T15:24:06.310809Z

as I said. shadow-cljs cljs-repl script will try to connect you to a process running the script that is created by that build

thheller 2024-10-19T15:24:25.396809Z

so you can run node main.js to create that node process

thheller 2024-10-19T15:24:43.301109Z

OR, instead you run shadow-cljs node-repl which manages the node process for you

andreiv 2024-10-19T15:24:57.546299Z

i launched shadow-cljs node-repl script shouldn't that work?

thheller 2024-10-19T15:24:57.952249Z

OR you eval (shadow.cljs.devtools.api/node-repl) in the CLJ REPL if you already have that connected

thheller 2024-10-19T15:25:18.682009Z

I cannot tell you how the conjure side of things works though

andreiv 2024-10-19T15:25:30.264299Z

yes I got the same result, i'm getting an error in a loop about a missing module but that is probably just a missing dep

andreiv 2024-10-19T15:35:33.931999Z

I've started both node-repl and a watch process, The REPL's prompt is`cljs.user` is that expected for a node REPL?

andreiv 2024-10-19T15:39:25.588519Z

I still get the no JS runtime error, I do have the node-repl and watch script running, and I connected to the REPL using Conjure's dedicated command for shadow-cljs

andreiv 2024-10-19T15:45:06.946119Z

; --------------------------------------------------------------------------------
; localhost:55038 (connected): /Users/andrei/dev/shadow-cljs-node/.shadow-cljs/nrepl.port
; --------------------------------------------------------------------------------
; Assumed session: Shih Tzu (Unknown )
; --------------------------------------------------------------------------------
; shadow-cljs (select): script
; (out) To quit, type: :cljs/quit
[:selected :script]

thheller 2024-10-19T15:47:36.742309Z

do you have an actujal node main.js process running is the question?

andreiv 2024-10-19T15:47:52.366349Z

I thought node-repl would manage it?

thheller 2024-10-19T15:48:14.446159Z

yes, it would. but I assume ; shadow-cljs (select): script means that you selected the REPL for the script build

andreiv 2024-10-19T15:48:16.958859Z

I tried running it now, my test quits immediatly it's just a println, should I put something in there for it to not quit?

thheller 2024-10-19T15:48:27.222449Z

this is from conjure, so I'm just guessing

andreiv 2024-10-19T15:48:48.035559Z

{:source-paths ["src"]
 :dependencies [
                [cider/cider-nrepl "0.24.0"]
                [org.clojure/core.async "1.5.648"]]
 :builds {:script {:target :node-script
                   :output-to "main.js"
                   :main foo/bar}}}

thheller 2024-10-19T15:49:34.486949Z

and the output from node main.js?

andreiv 2024-10-19T15:49:55.058989Z

it runs and prints

thheller 2024-10-19T15:49:59.395409Z

it should say shadow-cljs - #<a-number> ready!

andreiv 2024-10-19T15:50:15.759539Z

with an error after :

foo
SHADOW import error /Users/andrei/dev/shadow-cljs-node/.shadow-cljs/builds/script/dev/out/cljs-runtime/shadow.module.main.append.js

/Users/andrei/dev/shadow-cljs-node/.shadow-cljs/builds/script/dev/out/cljs-runtime/cljs/core.cljs:4014
   (if (.-cljs$lang$applyTo f)
 

thheller 2024-10-19T15:50:31.260199Z

ok. so whats the full error?

andreiv 2024-10-19T15:54:21.770059Z

ok I had to redo some things so now I have:

❯ shadow-cljs node-repl script

shadow-cljs - config: /Users/andrei/dev/shadow-cljs-node/shadow-cljs.edn
WARNING: The org.clojure/core.async dependency in shadow-cljs.edn was ignored. Default version is used and override is not allowed to ensure compatibility.
The versions provided by shadow-cljs can be found here: 

shadow-cljs - server version: 2.28.18 running at 
shadow-cljs - nREPL server started on port 56327

cljs.user=> shadow-cljs - #4 ready!


:^[WARNING: update-vals already refers to: #'clojure.core/update-vals in namespace: cider.nrepl.inlined-deps.orchard.v0v5v6.orchard.misc, being replaced by: #'cider.nrepl.inlined-deps.orchard.v0v5v6.orchard.misc/update-vals
WARNING: update-keys already refers to: #'clojure.core/update-keys in namespace: cider.nrepl.inlined-deps.orchard.v0v5v6.orchard.misc, being replaced by: #'cider.nrepl.inlined-deps.orchard.v0v5v6.orchard.misc/update-keys
❯ shadow-cljs watch script

shadow-cljs - config: /Users/andrei/dev/shadow-cljs-node/shadow-cljs.edn
shadow-cljs - connected to server
shadow-cljs - watching build :script
[:script] Configuring build.
[:script] Compiling ...
[:script] Build completed. (87 files, 0 compiled, 0 warnings, 0.40s)
and in Conjure:
; localhost:56327 (connected): /Users/andrei/dev/shadow-cljs-node/.shadow-cljs/nrepl.port
  ; --------------------------------------------------------------------------------
  ; Assumed session: Belgian Sheepdog (Unknown 
  ; --------------------------------------------------------------------------------
  ; shadow-cljs (select): script
  ; (err) No available JS runtime.
  ; (err) See 

andreiv 2024-10-19T15:54:32.317469Z

port is correct

thheller 2024-10-19T15:55:10.768929Z

ok. you are obviously confused and doing two things that are entirely unrelated to each other

thheller 2024-10-19T15:55:32.035389Z

shadow-cljs node-repl script is not a command. the script argument does absolutely nothing

thheller 2024-10-19T15:55:55.000739Z

shadow-cljs node-repl is a standalone node REPL that is not tied to any build. you can start it without any build config active at all

andreiv 2024-10-19T15:56:00.813959Z

i thought it was supposed to run the script build by that target

andreiv 2024-10-19T15:56:09.487129Z

ok

thheller 2024-10-19T15:56:30.864229Z

shadow-cljs (select): script I guess means that you didn't select the node-repl and instead want to talk to a REPL for your script build

thheller 2024-10-19T15:56:45.895419Z

that is completely separate and has nothing to do with node-repl

andreiv 2024-10-19T15:57:14.044319Z

ok I've launched just node-repl

thheller 2024-10-19T15:57:16.314589Z

so you do either one, not both

thheller 2024-10-19T15:57:24.617659Z

ok. that drops you right into the REPL

thheller 2024-10-19T15:57:50.745999Z

I cannot tell you how that works from the conjure side, or whether that works at all, but the terminal thing should be working just fine

andreiv 2024-10-19T15:57:57.344509Z

From the Conjure docs: To switch over to evaluating in our browser (or other JavaScript environment depending on your configuration) we must use :ConjureShadowSelect [build name] from within Neovim like so.

:ConjureShadowSelect app

andreiv 2024-10-19T15:58:05.787269Z

ok

thheller 2024-10-19T15:58:13.671629Z

ok, so that would then be :ConjureShadowSelect node-repl

andreiv 2024-10-19T15:58:23.159259Z

just $ shadow-cljs node-repl doesn't give me a REPL

andreiv 2024-10-19T15:58:32.246369Z

that isn't right, right?

thheller 2024-10-19T15:58:48.301229Z

hmm you just pasted that it did?

thheller 2024-10-19T15:58:56.224059Z

❯ shadow-cljs node-repl script

shadow-cljs - config: /Users/andrei/dev/shadow-cljs-node/shadow-cljs.edn
WARNING: The org.clojure/core.async dependency in shadow-cljs.edn was ignored. Default version is used and override is not allowed to ensure compatibility.
The versions provided by shadow-cljs can be found here: 

shadow-cljs - server version: 2.28.18 running at 
shadow-cljs - nREPL server started on port 56327

cljs.user=> shadow-cljs - #4 ready!

andreiv 2024-10-19T15:58:58.174509Z

THANK YOU

andreiv 2024-10-19T15:59:02.375069Z

this is it

thheller 2024-10-19T15:59:03.969889Z

the prompt is a bit garbled but it is there

andreiv 2024-10-19T16:00:06.284129Z

ok so this seems to work, I don't get why [build name] is somehow node-repl

andreiv 2024-10-19T16:00:14.240629Z

on the Conjure side

thheller 2024-10-19T16:00:42.664629Z

because shadow-cljs node-repl creates an implicit build named node-repl, one that is managed by shadow-cljs

andreiv 2024-10-19T16:01:11.399289Z

ah got it

andreiv 2024-10-19T16:01:34.179689Z

right ok the other option being make my own build and launch with node

thheller 2024-10-19T16:01:52.662169Z

yes, that would connect you to the node process you launch

thheller 2024-10-19T16:02:10.979509Z

(but if that crashes or exits early then obviously you can't connect to it)

andreiv 2024-10-19T16:03:23.296499Z

yeah this works well, thank you, this gets me as far as I wanted

andreiv 2024-10-19T15:10:43.315119Z

After reading the docs I set up my shadow-cljs.edn like this

{:source-paths ["src"]
 :dependencies [
                [cider/cider-nrepl "0.24.0"]
                [org.clojure/core.async "1.5.648"]]
 :builds {:script {:target :node-script
                   :output-to "main.js"
                   :main foo}}}
and now I get "No available JS runtime." when eval-ing it also fails to compile
[:script] Compiling ...
Invalid configuration
-- Spec failed --------------------

  {:target ...,
   :output-to ...,
   :main foo,
         ^^^
   :build-id ...}

should satisfy

  unquoted-qualified-symbol?
in src/foo.cljs: (ns foo (:require ["fs" :as fs]))

thheller 2024-10-19T15:15:50.675339Z

its not an ns, its a function you want to run

thheller 2024-10-19T15:16:05.032929Z

so (defn main [& args] ...) and then :main foo/main

andreiv 2024-10-19T15:16:28.294609Z

Thank you:! believe it or not i just realized it literally 1 second before i heard the notification sound 😄

thheller 2024-10-19T15:16:40.236809Z

"No available JS runtime" means that the created script is not running

thheller 2024-10-19T15:16:48.112309Z

if you just want a node-repl use shadow-cljs node-repl, build not required for that

andreiv 2024-10-19T15:16:54.783079Z

I think you did telepathy 🙂

andreiv 2024-10-19T15:17:25.159709Z

what do you mean by that command?

thheller 2024-10-19T15:18:16.602479Z

a REPL needs a place where the eval is actually executed

andreiv 2024-10-19T15:18:33.165889Z

I want to use it from Conjure

thheller 2024-10-19T15:18:44.678319Z

by default there is no running node process, so you create one. either by running your script or by launching a node-repl

thheller 2024-10-19T15:18:51.276929Z

see other thread

vemv 2024-10-19T19:52:05.430599Z

that's a very old cider-nrepl btw

👍 1