Fork me on GitHub
#shadow-cljs
<
2020-02-27
>
dpsutton05:02:22

The shadow users guide specifies that to use shadow-cljs with deps.edn you can add an alias with a different main. Using this from CIDER presents a problem as CIDER needs its own main to get nrepl started up and the middleware injected. It seems somehow we need to get the shadow server up and running. I tried (shadow.cljs.devtools.server/start!) and this is almost there. The problem is that this doesn't use the nrepl middleware so i just need to figure out how to get that up and going. Does anyone know of a good way to support this?

grav08:02:48

How to I retrieve __dirname from a cljs repl attached to a node-script (compiled with shadow)?

thheller08:02:20

js/__dirname

thheller08:02:52

actually it might not exist? its a special binding that only exists when loading files. so if it exists it likely is from the file that "loaded" the REPL code

sogaiu08:02:16

does (js* "dirname") not work?

thheller08:02:37

that is exactly identical to js/__dirname. literally no difference in the emitted code

sogaiu08:02:51

hmm...i thought one worked for me yesterday and not the other. i will double-check.

sogaiu08:02:37

thanks - i see the same for both. must have been confused.

sogaiu09:02:46

i confirm "dirname is not defined" at a cljs-repl and that it works in a :node-script target in a cljs file.

thheller09:02:04

__dirname is inherently tied to the current file ... REPL has no file so you probably shouldn't use it from the REPL 😛

4
grav09:02:17

ah ... 🙂 I guess what I meant was actually if I could use it from a node-script compiled with shadow. Not sure why I mentioned "repl" 😉 It seems Lumo handles it in a special way, so i thought maybe shadow also does? Already tried js/__dirname and it doesn't work. Edit: better link https://github.com/anmonteiro/lumo/commit/658732fb2b934569507db9cc9a845aea07918f0c

grav09:02:05

... or maybe it actually does work in a non-repl context. Will try again

thheller09:02:11

not sure what you mean. in :node-script you can of course access it?

grav09:02:39

Yup - works fine 🙂

grav09:02:50

Sorry for the noise, the whole problem was me trying to use it from the repl

thheller09:02:56

why are you asking anways? it is rarely a good idea to use __dirname?

grav09:02:31

I have some resources that I want to load - so I'd use __dirname for their base-path. Is there a better option?

thheller09:02:52

ah, hmm yeah thats ok I guess

👍 4
sogaiu13:02:11

good to hear -- i used __dirname to enable working with a .wasm file.

grav09:02:18

It's for a puppeteer script, so I have to resolve file:///[some-path]/foo.html

djanus10:02:36

hey! I'm trying to get an app to compile with shadow-cljs using Boot, via boot-shadow (https://github.com/degree9/boot-shadow)

djanus10:02:46

I'm getting this error:

djanus10:02:52

Compiling ClojureScript using shadow-cljs: release
[:web] Compiling ...
The required namespace "shadow.js" is not available, it was required by "braintree-2.26.0.min.js".

djanus10:02:25

the braintree thing is my native dependency, but it doesn't refer to shadow.js in any way

djanus10:02:34

I think it's some internal shadow-cljs thing

djanus10:02:14

the app builds fine with plain shadow-cljs, but I need to use Boot for now because of existing infrastructure

djanus10:02:24

has anyone stumbled into something similar before?

thheller11:02:08

@dj942 I suspect its a classpath issue. shadow/js.js should be on the classpath. boot does a lot of dynamic classpath magic so its easy to miss stuff

thheller11:02:27

(all JS code depends on shadow.js since that is the glue putting it all together)

djanus11:02:13

I just noticed that boot-shadow was using shadow-cljs 2.8.14; I've added an exclusion and manually specified 2.8.83, seems to be working now

flyboarder19:02:54

Could you open a PR for this issue if updating fixes it, also where did you pin the new shadow version in your project?

djanus15:02:18

I've pinned it in (set-env! :dependencies ...) in build.boot:

[degree9/boot-shadow "2.8.14-0" :scope "test" :exclusions [thheller/shadow-cljs]]
                   [thheller/shadow-cljs "2.8.83"]

djanus16:02:12

I'll try to whip up a PR when everything is working, but can't promise when

djanus11:02:12

(had to bump clojure to 1.10 as well, because tap>)

thheller11:02:21

thats really no different

thheller11:02:34

shadow.js existed in .14 too

thheller11:02:05

still good to update though

djanus11:02:07

yeah, i see

djanus11:02:15

no idea why .83 is more boot-friendly

djanus11:02:16

another question: with shadow-cljs, are React externs necessary to produce working release builds of reagent apps?

thheller11:02:32

likely no but maybe yes 😛

djanus11:02:58

I'll check 🙂

thheller11:02:08

I haven't used manual externs in a long time 😛

thheller11:02:20

just turn on :infer-externs :auto and you probably won't need any

djanus11:02:00

awesome! thanks for shadow-cljs

djanus11:02:12

it's my first foray into it and I'm amazed at how polished it is

👍 8
robert-stuttaford11:02:58

fair warning: you need manual externs for datascript

:compiler-options {:infer-externs :auto
                   :externs ["datascript/externs.js"]}

djanus11:02:34

thanks! I'm not using datascript, but it's still handy to keep in mind

djanus11:02:16

(it's also strange... why would a cljs library need externs?)

thheller12:02:53

because they don't follow the rules 😛

rickmoynihan12:02:20

I’m trying to figure out how to require and use a react-modal (https://github.com/reactjs/react-modal) Modal component in my reagent/shadow-cljs project… I’ve added react-modal to package.json and re run yarn and added the line (:require ["react-modal" :as react-modal]) to my ns form

rickmoynihan12:02:37

do I need to add a line like: (js/goog.exportSymbol "Modal" react-modal) too?

thheller12:02:29

only if you want an actual js/Modal global (which you shouldn't)

rickmoynihan12:02:02

how do I get a handle on Modal?

thheller12:02:16

what do you mean? you have it right there? react-modal?

rickmoynihan12:02:23

react-modal/Modal? gives me a reference error

thheller12:02:30

I'm not sure what you are asking? [:> react-modal ...]

rickmoynihan12:02:15

sorry slightly out of my depth in the react/js/cljs ecosystem

thheller12:02:44

if react-modal only has one export which is the actual modal then just use that directly

thheller12:02:12

(:require ["react-modal" :as Modal]) then [:> Modal ...] if that makes it clearer?

rickmoynihan12:02:44

:thumbsup: thanks that makes sense looks like it does just have one export too: https://github.com/reactjs/react-modal/blob/master/src/index.js

thheller12:02:58

ok thats a default export

thheller12:02:32

so it might be (:require ["react-modal" :default Modal])

thheller12:02:44

depends on how the package is actually bundled unfortunately

rickmoynihan12:02:50

ok I think I’ve got it working now with :as Modal. Thanks a million for your help!

Derek15:02:32

Release 2.8.88 seems to have broken the Inspect tab for me

Derek15:02:07

worker.js:126 WebSocket connection to '' failed: Error during WebSocket handshake: Unexpected response code: 403

thheller18:02:35

@dpassen1 see https://github.com/thheller/shadow-cljs/issues/660. it restricts access to localhost by default. how are you accessing it?

Derek19:02:07

Running npx shadow-cljs watch app on my dev machine and opening up a web browser to port 9000 (we override the port for the shadow-cljs dashboard http server)

Derek19:02:11

same machine

Derek19:02:14

no containers

thheller19:02:23

hmm forgot that websockets don't show the actual output

thheller19:02:48

what do you get when you load that page?

thheller19:02:59

probably using ipv6 by default?

Derek19:02:13

0:0:0:0:0:0:0:1 not trusted. Add :trusted-hosts #{"0:0:0:0:0:0:0:1"} in shadow-cljs.edn to trust.

thheller19:02:23

can you add that to shadow-cljs.edn to test?

thheller19:02:30

I'll add it as a default too

Derek19:02:08

fixes it for me

Derek19:02:36

when you work on shadow, what is your workflow? I was looking at adding a ‘name’ config option to the webservers for discoverability for our new engineers

Derek20:02:08

Thank you

thheller20:02:26

but currently requires a bit of additional setup since https://github.com/thheller/shadow-experiments has no formal release yet but is required by the ui

Derek20:02:38

Ah. I think I saw this error last night

Derek20:02:52

a grove ns that wasn’t found

thheller20:02:20

yeah you need to check out the experiments manually too

Derek20:02:28

Would you be opposed (in advance) to naming http-servers?

Derek20:02:09

When we start our app in development, we serve the dashboard at 9000, a version with api routes proxied to a local port on 9010, a version with api routes proxied to a remote dev instance on 9020, and the tests on 9999

Derek20:02:30

I’d love to have some way of identifying them on the dashboard

thheller21:02:45

how would you configure them?

Derek21:02:42

{:dev-http
 {9010
   {:root "..."
    :short-name "..."}
  9020
   {:root "..."
    :short-name "..."}
 ...}

Derek21:02:46

something like that

thheller21:02:30

I'd prefer :display-name

thheller21:02:45

or just :name is fine too I guess

Derek21:02:52

i don’t want to shadow a built in

thheller21:02:52

yeah as you can tell from the pr-str maybe I don't quite know how to display them

thheller21:02:09

the roots typically are enough for me

Derek21:02:27

If we had one, I’d agree

Derek21:02:41

How does shadow.experiments.grove/<< handle nil?

Derek21:02:20

Ok cool. It makes sense to guard it behind a when or when-let

otwieracz20:02:41

Hmm. I wanted to use shadow-cljs just for REPL at this moment - so I had no builds defined (I do not target browser yet). But I was unable to run shadow-cljs in Calva in VSCode due to something something nil error (builds list was empty).

pez22:02:47

Seems like an issue in Calva.

kaosko21:02:30

do I have some kind of version conflict with dependencies when I get this: The required namespace "goog.html.TrustedResourceUrl" is not available, it was required by "goog/html/safeurl.js".

thheller21:02:52

closure-library

thheller21:02:46

kinda weird I guess but not sure what else it would be

kaosko21:02:23

how do I fix it?

thheller21:02:11

I don't know. what do you use? lein? deps.edn?

thheller21:02:46

lein deps :tree and fix the conflicts