Fork me on GitHub
#shadow-cljs
<
2022-12-02
>
Crispin02:12:08

Hi everyone. I'm trying to load a shadow build code module (code splitting) at run time into the browser and when I do the shadow.loader/load I get shadow.loader API was called before shadow.loader.init! You are probably calling module loader too early before shadow-cljs got fully initialized.

Crispin02:12:30

shadow-cljs.edn build looks like:

Crispin02:12:38

:builds
 {:main
  {:target :browser
   :output-dir "resources/public/cljs-out"
   :asset-path "/app"
   :build-hooks
   [(shadow.cljs.build-report/hook
      {:output-to "builds/report.html"})]
   :modules
   {:base {:entries []}
    :main {:entries [myproject.web-app.main]
           :depends-on #{:base}}
    :pdf-viewer {:entries [myproject.web-app.pdf-viewer]
                 :depends-on #{:base}}}
   }}}

Crispin02:12:36

:main is all loaded, and then when I do any load, for example (shadow.loader/with-module "pdf-viewer" #(js/alert "LOADED")) I get the:

shadow.loader API was called before shadow.loader.init!
You are probably calling module loader too early before shadow-cljs got fully initialized.

Crispin02:12:27

Calling init myself does nothing. Because it's not initialising. I think.

Crispin02:12:31

digging in, I notice here: https://github.com/thheller/shadow-cljs/blob/7fefe5b3f604ff11d33539e4899e160dd1ff6eb0/src/main/shadow/loader.js#L42 that init is only done if goog.global.shadow$modules is defined. In my browser session it is not defined

Crispin02:12:59

>> goog.global.shadow$modules
undefined

thheller06:12:59

@U1QQJJK89 if you intend to use the loader you must set :module-loader true in the build config

💋 1
Crispin06:12:41

That worked. Now going back to the docs I can see that written clearly, but somehow I just didn't see that at the time. facepalm

Crispin06:12:57

Thankyou for an awesome tool