Fork me on GitHub
#shadow-cljs
<
2022-11-14
>
roklenarcic20:11:57

I’ve got a bit of a problem operating the CLJS REPL via remote nREPL. When I connect with remote REPL I select the build repl:

Connecting to remote nREPL server...
Clojure 1.11.1
(shadow/nrepl-select :main)
To quit, type: :cljs/quit
=> [:selected :main]
And in this namespace I have imports:
(ns dev-test
  (:require [com.fulcrologic.fulcro.data-fetch :as df]
            )
But it seems that the requires just don’t work. They work in the app, just not in the REPL:
df/load!
------ WARNING - :undeclared-ns ------------------------------------------------
 Resource: <eval>:1:1
 No such namespace: df, could not locate df.cljs, df.cljc, or JavaScript source providing "df"
--------------------------------------------------------------------------------

------ WARNING - :undeclared-var -----------------------------------------------
 Resource: <eval>:1:1
 Use of undeclared Var df/load!
--------------------------------------------------------------------------------

=> nil
::df/id
[line 1, col 8] Invalid keyword: ::df/id.

=> nil
It does work if I write this:
(require '[com.fulcrologic.fulcro.data-fetch :as df])
=> nil
df/load!
=> #object[com$fulcrologic$fulcro$data_fetch$load_BANG_]
What gives?

roklenarcic20:11:08

Hm I think it might be the namespace is never loaded

thheller20:11:46

this is the normal expected behavior yes

thheller20:11:46

you must load a namespace and switch to it manually

thheller20:11:57

by default when starting a REPL you start in the cljs.user namespace

thheller20:11:21

depending on which commands you use loading and switching may be separate commands

roklenarcic20:11:28

I’ve tried to load the namespace manually but that didn’t work

thheller20:11:40

loaded how and what didn't work?

roklenarcic20:11:47

but that might be a problem with Cursive

thheller21:11:07

unlikely. I use Cursive myself and never had any issues with the REPL

roklenarcic21:11:19

Basically to fix it I had to include the NS in require statement of the root app ns

thheller21:11:31

this doesn't tell me anything

roklenarcic21:11:33

I’ll test this again I think, there might be some other issue at play

thheller21:11:37

> And in this namespace I have imports:

thheller21:11:51

why did you list this ns specifically? what did you do with it?

thheller21:11:57

the mere presence of it does nothing on its own

roklenarcic21:11:32

I think the problem was that the folder was not part of the CLJS build

thheller21:11:12

if its a REPL only ns it probably shouldn't be

roklenarcic21:11:07

Goes like this:

Connecting to remote nREPL server...
Clojure 1.11.1
(shadow/nrepl-select :main)
To quit, type: :cljs/quit
=> [:selected :main]
(in-ns 'roklenarcic.cookery.dev-cli)
=> nil
Loading src/main/roklenarcic/cookery/ui/category.cljs... 
------ WARNING - :redef --------------------------------------------------------
 Resource: <eval>:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------


config
------ WARNING - :undeclared-var -----------------------------------------------
 Resource: <eval>:1:1
 Use of undeclared Var /config
--------------------------------------------------------------------------------

=> nil

roklenarcic21:11:30

so in cursive I’ve changed the NS and then loaded the NS

thheller21:11:34

(in-ns 'roklenarcic.cookery.dev-cli) doesnt' load the ns, it only switches to it

roklenarcic21:11:46

right but the next command loaded it

thheller21:11:04

and if you reverse the order of those commands?

thheller21:11:18

it says Loading src/main/roklenarcic/cookery/ui/category.cljs...

thheller21:11:29

that is not roklenarcic.cookery.dev-cli

roklenarcic21:11:31

ah the warning stops the load?

roklenarcic21:11:42

the redef warning

thheller21:11:00

I'm unsure what you are asking now

roklenarcic21:11:24

I am triggering the load with CMD+Shift+L in roklenarcic.cookery.dev-cli

thheller21:11:26

(in-ns 'roklenarcic.cookery.dev-cli) this is likely the first problem

roklenarcic21:11:42

but it says

Loading src/main/roklenarcic/cookery/ui/category.cljs... 
------ WARNING - :redef --------------------------------------------------------

thheller21:11:44

I don't know what that keybinding is

thheller21:11:52

which cursive command does it execute?

roklenarcic21:11:59

it’s cursive for load NS of current file

thheller21:11:24

again. can we please start at step 1?

roklenarcic21:11:29

so the category.cljs is required from this one so I am assuming that warning prevent compilation

thheller21:11:47

otherwise you might be starting out at some weird broken state that causes all other weird stuff

thheller21:11:46

I cannot see your code so I don't know what these namespaces are doing. so for me there is a lot of guessing involved which makes every step harder to debug 😛

roklenarcic21:11:36

dev-cli is an empty ns with multiple requires to other namespaces, nothing else at this point

thheller21:11:46

then it is NOT empty

thheller21:11:35

but to be extra clear hear: if you issue an in-ns WITHOUT the namespace being already loaded that is an ERROR

thheller21:11:47

so, either load that namespace first properly

thheller21:11:52

or don't issue that command at all

thheller21:11:16

warnings will also stop the load of the namespace

roklenarcic21:11:25

I think the main problem is that namespace that is required that produces a warning, if I comment that one out then things work as expected

roklenarcic21:11:40

Now I just need to fix

------ WARNING - :redef --------------------------------------------------------
 Resource: <eval>:33:1
 abs already refers to: cljs.core/abs being replaced by: cljc.java-time.duration/abs
--------------------------------------------------------------------------------
somehow

roklenarcic21:11:05

that’s in a library I use somewhere so I cannot affect the code directly

thheller21:11:26

likely just need to update that library?

roklenarcic21:11:13

let’s hope so… thanks

thheller21:11:33

just for correctness sake

thheller21:11:47

before in-ns you should do (require 'roklenarcic.cookery.dev-cli)

thheller21:11:50

otherwise in-ns will just issue a blank (ns roklenarcic.cookery.dev-cli) which means your require aliases won't be available