Fork me on GitHub
#shadow-cljs
<
2021-12-20
>
Pepijn de Vos15:12:04

I'm having a problem where advanced compilation and code splitting don't work together. I split my code in a common module and two page-specific ones, but one of the page-specific ones gives an error that $APP.qr is undefined. If I switch to simple compilation it works fine, if I compile everything into a single file it also works fine, but with advanced compilation and multiple modules it breaks. So for now I've just switched to using one single file, but if anyone has any clue what's going on it'd be appreciated This is the commit that works around it, in case you want to explore the code before/after: https://github.com/NyanCAD/Mosaic/commit/b1f484942e89509246c88b3ad12ad53c445088da

Ryan15:12:38

Hey all, awhile back I was having trouble with node modules not getting compiled in, seemingly at random. The frequency this is occuring has increased, leading me to need to remove my .shadow-cljs/builds directory frequently to prevent broken builds. Any clues as to what could cause something like this? or perhaps a clue as to where to start looking? 🙂 Thanks

thheller17:12:06

@pepijndevos run the build with shadow-cljs release frontend --pseudo-names to get an idea what $APP.qr might be

Pepijn de Vos17:12:33

$APP.$cljs$spec$alpha$t_cljs$0spec$0alpha11756$$ color me somewhat surprised

thheller17:12:44

ah so yeah thats a known issue

thheller17:12:15

let me find the ticket for that

thheller17:12:25

so basically use spec assert once in a namespace that ends up in :common

Pepijn de Vos17:12:23

Ah! Glad to hear it's a known issue. At the moment my app is relatively small so it's fine to just compile everything in a single module rather than have weird hacks, but as the app grows it's great to know I have that escape hatch available. Thanks!

thheller17:12:21

@rdonahue define "node modules not getting compiled in"?

Ryan18:12:14

The app won't load at all, and the js console will show an error like: "Module not provided: Button" .. the last module it displayed that error with was '18', so not sure what that means. It was in production, so didn't have time to really capture much else, had to wipe the builds folder and re-build.

thheller18:12:50

are you maybe caching or mixing builds?

thheller18:12:05

no one else has ever reported issues such as this so I really don't know what this might be about

thheller18:12:22

mixing as in loading the output of two different builds on the same page?

thheller18:12:38

maybe of the same build but compiled at different times?

thheller18:12:17

or partially caching some (eg. multiple modules but having a stale older version in cache)?

Ryan19:12:28

I don't think so, at least not on purpose.

Ryan19:12:31

I have the local-dev resource root, and a production root, which gets rebuilt from the local-dev one on each build, then a fresh prod build is built into that resource root

Ryan19:12:55

compiles via

npx  shadow-cljs release app
and the config is setup to use the production root

Ryan19:12:45

{:app {:target :browser
        :output-dir "local-dev/public/js/compiled"
        :asset-path "/js/compiled"
        :module-hash-names true
        :modules {:pnx-web {:init-fn pnx-web.core/init}}
        :devtools {:preloads [day8.re-frame-10x.preload]}
        :dev {:compiler-options
         {:closure-defines
          {re-frame.trace.trace-enabled? true
           day8.re-frame.tracing.trace-enabled? true}}}
        :release {:output-dir "release/public/js/compiled"}
        :build-options {:ns-aliases {day8.re-frame.tracing day8.re-frame.tracing-stubs}}}
is app definition

thheller06:12:03

that all looks fine

thheller06:12:35

are there any other errors BEFORE you get the module not provided error that would just cause this as a secondary effect?

Chase22:12:35

I'm trying to use an environment variable and could use some help. I have the variable saved in my .bashrc as OPEN_WEATHER and in my shadow-cljs.edn I have: :closure-defines {API-KEY #shadow/env "OPEN_WEATHER"} but when I try to use it in my app by referring to API-KEY I get an undeclared var error.

dpsutton22:12:57

the var seems to need to be fully namespace qualified from the examples

Chase22:12:19

I was just trying that after looking back over that documentation.

dpsutton22:12:25

(ns )

(goog-define VERBOSE false)
and in shdaow-cljs.edn
:dev {:closure-defines { true}}
   ;; to enable always
   :closure-defines { true}

Chase22:12:53

Waiting for the compile now

Chase22:12:18

hmmm, I changed it to ...{weather.core/API-KEY #shadow/env... and still getting the undeclared variable error...

dpsutton22:12:56

in (ns weather.core ...) do you have (good-define API-KEY "dev") or something similar?

Chase22:12:24

oh nope. I was just trying to call it like it was an already declared variable

dpsutton22:12:40

the documentation shows how to use it

Chase22:12:20

I'm not seeing that

Chase22:12:50

Ok, I have to step away but I'll return back. it's confusing me.

Chase22:12:42

So in my clj file I put something like (goog-define API-KEY "") and then that gets overridden by the shadow-cljs compiler?

dpsutton22:12:29

that’s correct

dpsutton22:12:48

i’d put “dummy” or “closure-define” or something like that but yeah

Chase23:12:57

Awesome. Makes sense. Thanks so much