Fork me on GitHub
#shadow-cljs
<
2023-03-25
>
frozenlock13:03:26

Howdy folks! I'm trying to migrate from lein-figwheel to shadow-cljs and I'm having a hard time šŸ˜… (I'm using lein-shadow to still be able to use lein) When I run lein shadow compile app it says the following:

The required namespace "myapp.core" is not available.
Any hint as to what could be the issue?

thheller13:03:41

incorrect :source-paths in project.clj. note that I strongly discourage using lein-shadow. you can just set :lein true in shadow-cljs and it'll use lein for dependency management

frozenlock13:03:05

Oh interesting, I'll try this approach then

frozenlock13:03:15

I think I'm getting there

frozenlock13:03:40

I get this error when I try to browse to the server:

[:browser-repl] Build completed. (115 files, 0 compiled, 0 warnings, 1.50s)
cljs.user=> Mar. 25, 2023 9:45:43 A.M. io.undertow.server.Connectors executeRootHandler
ERROR: UT005071: Undertow request failed HttpServerExchange{ GET /}
java.lang.IllegalArgumentException: No implementation of method: :respond of protocol: #'shadow.undertow.impl/RespondBody found for class: java.nio.HeapByteBuffer
	at clojure.core$_cache_protocol_fn.invokeStatic(core_deftype.clj:584)
...

frozenlock14:03:13

Ahhhh so close I extended the protocol and now the handler is correctly served

(require 'shadow.undertow.impl)
(import '[io.undertow.server HttpServerExchange])

(extend-protocol shadow.undertow.impl/RespondBody
  
  java.nio.ByteBuffer
  (respond [buf ^HttpServerExchange exchange]
    (let [out (.getOutputStream exchange)]
      (while (.hasRemaining buf)
        (.write out (byte-array [(byte (.get buf))])))
      (.flush out))))
Unfortunately the compiled JS is nowhere to be found. Might just be a path issue

frozenlock14:03:37

Ok, so running shadow-cljs watch app

[:app] Configuring build.
[:app] Compiling ...
[:app] Build failure:
The required namespace "react" is not available, it was required by "reagent/core.cljs".

frozenlock14:03:58

But I know react is in the dependencies.

[reagent "0.10.0"]
   [cljsjs/react-dom-server "16.13.0-0"]
   [cljsjs/react-dom "16.13.0-0"]
   [cljsjs/react "16.13.0-0"]

frozenlock14:03:56

So why doesn't shadow-cljs see it? :thinking_face:

thheller15:03:58

note that I recommend running your own server, and not using the shadow-cljs dev-http as your server. hot-reload/repl will still work, even with your own server

šŸ‘ 2
Michaƫl Salihi17:03:34

Hi, I have hard time to make working this lib with Shadow-cljs https://github.com/cjohansen/portfolio. I miss surely some classpath config or something like that. Ex. The lib load dynamically some assets https://github.com/cjohansen/portfolio/blob/main/src/portfolio/client.cljs#L60 and use it's own resources here: https://github.com/cjohansen/portfolio/tree/main/resources/public/portfolio Is it possible to setup classpath to use resources coming from the jar ?

thheller17:03:16

sure. :dev-http {8080 ["classpath:public" "public"]}}

Michaƫl Salihi18:03:28

Perfect, I was on the right path but putting classpath:resources/public , thanks!