Fork me on GitHub
#shadow-cljs
<
2022-05-17
>
pez08:05:11

At my day job we have mostly ClojureScript projects, but one project is being ported to NextJS. This is a browser project. We have some libraries written in ClojureScript that we want to consume from the NextJS project. What are our options if we do not want to load several instances of the ClojureScript runtime? Since it is only one JS project maybe it would work to build one browser module with one endpoint per CLJS library? Any new JS projects would do something similar.

henryw37410:05:14

hi @thheller. since the last cljs release, data_readers.cljc containing reader conditionals works. for example:

#?(:clj {}
   :cljs {foo/bar my.project.foo/bar})
but this does not work in shadow. It looks like `
(cljs.analyzer/load-data-readers)
is not getting called as it does when invoking cljs.build.api/build

thheller11:05:22

they are opt-in in shadow-cljs. you need to set :compiler-options {:data-readers true} in the build config

thheller11:05:11

no clue if it works then though. I don't think data readers should ever be used for anything directly in source code

henryw37411:05:13

also, tags from data_readers.cljc files are used when reading data with cljs.reader fns

thheller11:05:55

yeah, and I don't ever want those to leak into my build just because they are on the classpath

thheller11:05:36

it also creates certain "undefined load order" issues since things break if you don't actually ever require the namespaces uses in those directly

thheller11:05:31

if you do all bets are off regarding caching and build reliability. so use with care.

henryw37411:05:28

thanks I'll try that. I use them at the repl

henryw37411:05:08

it's not working. in shadow I see

;; taken from cljs.closure since its private there ...
(defn load-data-reader-file [mappings ^java.net.URL url]
in shadow.build.classpath . the load-.. fn has moved to cljs.analyzer and is still private. although e.g.
(cljs.analyzer/load-data-readers)
is public, with memoized and unmemoized versions

thheller12:05:53

please create an issue for this. can't get to it right now

πŸ‘ 1
timo12:05:58

Hi, I am getting

Execution error (AWTError) at sun.awt.X11GraphicsEnvironment/initDisplay (X11GraphicsEnvironment.java:-2).
Can't connect to X11 window server using '172.18.32.204
when running npx shadow-cljs browser-repl . I am inside a VM without X-server. Anyone has an idea?

timo12:05:43

ok got it, sorry

Samuel McHugh15:05:28

Seeing

Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:476).
com.google.javascript.jscomp.JSModule
Unfortunately haven't been able to reproduce this issue in a simple project. Using
org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/clojurescript {:mvn/version "1.11.51"}
thheller/shadow-cljs {:mvn/version "2.19.0"}
I'll include the full stacktrace in this thread.

βœ… 1
thheller15:05:30

very likely to be a dependency conflict. make sure you have the appropriate closure-compiler and cljs versions (guessing you are using project.clj or deps.edn to manage dependencies)

thheller15:05:29

check which closure-compiler version oyu are getting via clj -A:your-aliases -Stree or so

βœ… 1
Samuel McHugh15:05:49

org.clojure/clojurescript 1.11.51
  . com.google.javascript/closure-compiler-unshaded v20220502 :newer-version
This?

thheller15:05:58

seems correct

thheller15:05:51

run clj -A:your-aliases and then (require ')

thheller15:05:15

( "com/google/javascript/jscomp/JSModule.class")

thheller15:05:07

seems like your dependencies got messed up somehow

thheller15:05:42

this file isn't supposed to exist

thheller15:05:08

you do actually use deps.edn to manage dependencies correct? there is a :deps true or :deps {:aliases ...} in your shadow-cljs.edn?

thheller15:05:31

you seem to have a old shadow-cljs version? JSModule has been gone for a while now

thheller15:05:00

check ( "shadow/build/closure.clj")

Samuel McHugh15:05:45

#object[java.net.URL 0x7af707e0 "jar:file:/home/foobar/.m2/repository/thheller/shadow-cljs/2.19.0/shadow-cljs-2.19.0.jar!/shadow/build/closure.clj"

Samuel McHugh15:05:05

But fair enough. I'm working in a mono repo with lots of projects, most of which are on old versions of shadow. I'd expect -Stree to have revealed that the old shadow is being used but maybe there is something else funky going on.

thheller15:05:59

hmm yeah dunno. that file is definitely not trying to load JSModule anywhere

thheller15:05:11

(it was renamed to JSChunk a while ago in the closure-compiler)

thheller15:05:51

my guess is an incompatible mix of shadow-cljs, cljs and closure-compiler somewhere

thheller15:05:06

closure compiler version you can check via ( "com/google/javascript/jscomp/JSChunk.class")

thheller15:05:14

I'd assume that exists

thheller15:05:38

maybe some bad leftover AOT code? so try ( "shadow/build/closure__init.class")

Samuel McHugh15:05:40

#object[java.net.URL 0x7da10b5b "jar:file:/home/foobar/.m2/repository/com/google/javascript/closure-compiler-unshaded/v20220502/closure-compiler-unshaded-v20220502.jar!/com/google/javascript/jscomp/JSChunk.class"]
and
nil
respectively

thheller15:05:31

that all looks fine. assuming that is what the classpath actually is when shadow-cljs runs

thheller15:05:56

I mean you can just (require 'shadow.build.closure) in the REPL

thheller15:05:01

that should be fine then

Samuel McHugh15:05:37

Found the issue... 🀯 There are actually 2 shadow builds that run in parallel when I call a script and so the error messaging was coming from that second build which I never pay attention to. Oops. And ofcourse it has its own deps.edn and so I was checking in the repl sourcing the wrong deps.edn. TLDR: running stuff in parallel makes logs confusing πŸ™‚

Samuel McHugh16:05:59

Thanks for your help. Much appreciated

yura parenyuk20:05:12

Hello everyone! I am in need of help with installation of shadow-cljs. I'm trying to add syncfusion dependency, but it's giving error: The required JS dependency "@syncfusion/ej2-react-layout" is not available, it was required by "poc/core.cljs".

thheller20:05:55

did you install it via npm install @syncfusion/ej2-react-layout in the project dir?

yura parenyuk20:05:40

It's in package.json, and I have it installed too.

thheller20:05:47

quick google suggest the package name is actually @syncfusion/ej2-react-layouts. so you are missing an s?

πŸ‘€ 1
πŸ‘ 1
yura parenyuk20:05:36

Oh... my ... :man-facepalming:

yura parenyuk22:05:37

Hi @thheller, I have coded the the components, it's compiling successfully, but output is not showing.

yura parenyuk22:05:50

It means I've coded the components, but there's something wrong with Interop. Right?

thheller22:05:29

don't have a clue. I know neither the library you are using nor the interop lib. I also haven't used react in many years. ask in the appropriate channel.